This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
def params(n): | |
fn = range(n) | |
return {'name': 'a', 'args': fn, 'ids': ['a: {}'.format(i) for i in fn]} | |
named_args = params(3) | |
@pytest.mark.parametrize( | |
named_args['name'], named_args['args'], ids=named_args['ids']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# written in python2.7 | |
def bad(n): | |
if n == 1: | |
raise ValueError('n is 1!') | |
if n == 2: | |
raise TypeError('n is 2!') | |
return n, 2*n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Generate/verify memes in Prolog. | |
noun(apple). | |
noun(banana). | |
noun(orange). | |
noun(kiwifruit). | |
irregular_noun(kiwifruit, kiwifruit). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
@pytest.mark.parametrize("input", "expected", [ | |
("3+5", 8), | |
("2+4", 6), | |
]) | |
def test_evalPassing(input, expected): | |
assert eval(input) == expected | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pytest_generate_tests(metafunc): | |
""" | |
If the test_ fn has a idparametrize mark, use it to create parametrized | |
tests with ids. Instead of giving a list of argvals (test values), it | |
should be a dict of test id strings -> tuple of test values | |
e.g. | |
@py.test.mark.idparametrize(('a', 'b'), { | |
'foo': (1, 2), | |
'bar': (3, 4), | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Public domain, yo. | |
See http://brianna.laugher.id.au/blog/79/the-progressive-speaking-stack-in-python for background. | |
""" | |
class Speaker: | |
def __init__(self, name): | |
self.name = name | |
self._hasSpoken = False | |
def __eq__(self, other): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I/dalvikvm( 1836): Failed resolving Lorg/thoughtcrime/securesms/ConversationListFragment$1; interface 573 'Landroid/widget/SearchView$OnQueryTextListener;' | |
W/dalvikvm( 1836): Link of class 'Lorg/thoughtcrime/securesms/ConversationListFragment$1;' failed | |
E/dalvikvm( 1836): Could not find class 'org.thoughtcrime.securesms.ConversationListFragment$1', referenced from method org.thoughtcrime.securesms.ConversationListFragment.initializeSearch | |
W/dalvikvm( 1836): VFY: unable to resolve new-instance 1205 (Lorg/thoughtcrime/securesms/ConversationListFragment$1;) in Lorg/thoughtcrime/securesms/ConversationListFragment; | |
D/dalvikvm( 1836): VFY: replacing opcode 0x22 at 0x0000 | |
D/dalvikvm( 1836): VFY: dead code 0x0002-0008 in Lorg/thoughtcrime/securesms/ConversationListFragment;.initializeSearch (Landroid/widget/SearchView;)V | |
E/dalvikvm( 1836): Could not find class 'android.widget.SearchView', referenced from method org.thoughtcrime.securesms.ConversationListFragment.onPrepareOptionsMenu | |
W/dalvikvm( 1836): VFY: unable to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These are snippets of py.test in action, used in a talk given at | |
PyCon AU 2012 in Hobart, Tasmania. They are all relevant for | |
py.test 2.2 except where specified. Where taken from open source | |
projects I have listed a URL, some examples are from the py.test | |
documentation, some are from my workplace. | |
Apart from things called test_*, these functions should probably | |
be in your conftest.py, although they can generally start life in | |
your test files. |
NewerOlder