regenerating examples

This commit is contained in:
holger krekel
2010-11-26 13:26:56 +01:00
parent ca72c162c8
commit f1fc6e5eb6
17 changed files with 190 additions and 170 deletions

View File

@@ -49,15 +49,15 @@ You can now run the test::
$ py.test test_sample.py
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev30
test path 1: test_sample.py
platform linux2 -- Python 2.6.5 -- pytest-2.0.0
collecting ... collected 1 items
test_sample.py F
================================= FAILURES =================================
_______________________________ test_answer ________________________________
mysetup = <conftest.MySetup instance at 0x16f5998>
mysetup = <conftest.MySetup instance at 0x2c88128>
def test_answer(mysetup):
app = mysetup.myapp()
@@ -122,12 +122,12 @@ Running it yields::
$ py.test test_ssh.py -rs
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev30
test path 1: test_ssh.py
platform linux2 -- Python 2.6.5 -- pytest-2.0.0
collecting ... collected 1 items
test_ssh.py s
========================= short test summary info ==========================
SKIP [1] /tmp/doc-exec-107/conftest.py:22: specify ssh host with --ssh
SKIP [1] /tmp/doc-exec-474/conftest.py:22: specify ssh host with --ssh
======================== 1 skipped in 0.02 seconds =========================

View File

@@ -27,8 +27,8 @@ now execute the test specification::
nonpython $ py.test test_simple.yml
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev30
test path 1: test_simple.yml
platform linux2 -- Python 2.6.5 -- pytest-2.0.0
collecting ... collected 2 items
test_simple.yml .F
@@ -37,9 +37,7 @@ now execute the test specification::
usecase execution failed
spec failed: 'some': 'other'
no further details known at this point.
========================= short test summary info ==========================
FAIL test_simple.yml::hello
==================== 1 failed, 1 passed in 0.06 seconds ====================
==================== 1 failed, 1 passed in 0.03 seconds ====================
You get one dot for the passing ``sub1: sub1`` check and one failure.
Obviously in the above ``conftest.py`` you'll want to implement a more
@@ -58,8 +56,8 @@ reporting in ``verbose`` mode::
nonpython $ py.test -v
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev30 -- /home/hpk/venv/0/bin/python
test path 1: /home/hpk/p/pytest/doc/example/nonpython
platform linux2 -- Python 2.6.5 -- pytest-2.0.0 -- /home/hpk/venv/0/bin/python
collecting ... collected 2 items
test_simple.yml:1: usecase: ok PASSED
test_simple.yml:1: usecase: hello FAILED
@@ -69,9 +67,7 @@ reporting in ``verbose`` mode::
usecase execution failed
spec failed: 'some': 'other'
no further details known at this point.
========================= short test summary info ==========================
FAIL test_simple.yml::hello
==================== 1 failed, 1 passed in 0.06 seconds ====================
==================== 1 failed, 1 passed in 0.03 seconds ====================
While developing your custom test collection and execution it's also
interesting to just look at the collection tree::

View File

@@ -41,11 +41,12 @@ Running it means we are two tests for each test functions, using
the respective settings::
$ py.test -q
collecting ... collected 4 items
F..F
================================= FAILURES =================================
_________________________ TestClass.test_equals[0] _________________________
self = <test_parametrize.TestClass instance at 0x128a638>, a = 1, b = 2
self = <test_parametrize.TestClass instance at 0x26ef2d8>, a = 1, b = 2
def test_equals(self, a, b):
> assert a == b
@@ -54,7 +55,7 @@ the respective settings::
test_parametrize.py:17: AssertionError
______________________ TestClass.test_zerodivision[1] ______________________
self = <test_parametrize.TestClass instance at 0x1296440>, a = 3, b = 2
self = <test_parametrize.TestClass instance at 0x26fa758>, a = 3, b = 2
def test_zerodivision(self, a, b):
> pytest.raises(ZeroDivisionError, "a/b")
@@ -97,11 +98,12 @@ for parametrizing test methods::
Running it gives similar results as before::
$ py.test -q test_parametrize2.py
collecting ... collected 4 items
F..F
================================= FAILURES =================================
_________________________ TestClass.test_equals[0] _________________________
self = <test_parametrize2.TestClass instance at 0x1dbcc68>, a = 1, b = 2
self = <test_parametrize2.TestClass instance at 0x1e5e638>, a = 1, b = 2
@params([dict(a=1, b=2), dict(a=3, b=3), ])
def test_equals(self, a, b):
@@ -111,7 +113,7 @@ Running it gives similar results as before::
test_parametrize2.py:19: AssertionError
______________________ TestClass.test_zerodivision[1] ______________________
self = <test_parametrize2.TestClass instance at 0x1dd0488>, a = 3, b = 2
self = <test_parametrize2.TestClass instance at 0x1e6f560>, a = 3, b = 2
@params([dict(a=1, b=0), dict(a=3, b=2)])
def test_zerodivision(self, a, b):
@@ -138,5 +140,6 @@ with different sets of arguments for its three arguments::
Running it (with Python-2.4 through to Python2.7 installed)::
. $ py.test -q multipython.py
collecting ... collected 75 items
....s....s....s....ssssss....s....s....s....ssssss....s....s....s....ssssss
48 passed, 27 skipped in 2.55 seconds
48 passed, 27 skipped in 2.74 seconds

View File

@@ -13,9 +13,8 @@ get on the terminal - we are working on that):
assertion $ py.test failure_demo.py
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev38
collecting ...
collected 35 items
platform linux2 -- Python 2.6.5 -- pytest-2.0.0
collecting ... collected 35 items
failure_demo.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@@ -31,7 +30,7 @@ get on the terminal - we are working on that):
failure_demo.py:15: AssertionError
_________________________ TestFailing.test_simple __________________________
self = <failure_demo.TestFailing object at 0x2c9da90>
self = <failure_demo.TestFailing object at 0x17d8750>
def test_simple(self):
def f():
@@ -41,21 +40,21 @@ get on the terminal - we are working on that):
> assert f() == g()
E assert 42 == 43
E + where 42 = <function f at 0x2c447d0>()
E + and 43 = <function g at 0x2c44cf8>()
E + where 42 = <function f at 0x17e2488>()
E + and 43 = <function g at 0x17e2140>()
failure_demo.py:28: AssertionError
____________________ TestFailing.test_simple_multiline _____________________
self = <failure_demo.TestFailing object at 0x2c9dc90>
self = <failure_demo.TestFailing object at 0x17d4390>
def test_simple_multiline(self):
otherfunc_multi(
42,
> 6*9)
failure_demo.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
failure_demo.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a = 42, b = 54
@@ -67,19 +66,19 @@ get on the terminal - we are working on that):
failure_demo.py:12: AssertionError
___________________________ TestFailing.test_not ___________________________
self = <failure_demo.TestFailing object at 0x2c93f10>
self = <failure_demo.TestFailing object at 0x17d8cd0>
def test_not(self):
def f():
return 42
> assert not f()
E assert not 42
E + where 42 = <function f at 0x2ca1050>()
E + where 42 = <function f at 0x17e25f0>()
failure_demo.py:38: AssertionError
_________________ TestSpecialisedExplanations.test_eq_text _________________
self = <failure_demo.TestSpecialisedExplanations object at 0x2c9d9d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x17e33d0>
def test_eq_text(self):
> assert 'spam' == 'eggs'
@@ -90,7 +89,7 @@ get on the terminal - we are working on that):
failure_demo.py:42: AssertionError
_____________ TestSpecialisedExplanations.test_eq_similar_text _____________
self = <failure_demo.TestSpecialisedExplanations object at 0x2a04e90>
self = <failure_demo.TestSpecialisedExplanations object at 0x17ee990>
def test_eq_similar_text(self):
> assert 'foo 1 bar' == 'foo 2 bar'
@@ -103,7 +102,7 @@ get on the terminal - we are working on that):
failure_demo.py:45: AssertionError
____________ TestSpecialisedExplanations.test_eq_multiline_text ____________
self = <failure_demo.TestSpecialisedExplanations object at 0x2c9d710>
self = <failure_demo.TestSpecialisedExplanations object at 0x17d8d10>
def test_eq_multiline_text(self):
> assert 'foo\nspam\nbar' == 'foo\neggs\nbar'
@@ -116,7 +115,7 @@ get on the terminal - we are working on that):
failure_demo.py:48: AssertionError
______________ TestSpecialisedExplanations.test_eq_long_text _______________
self = <failure_demo.TestSpecialisedExplanations object at 0x2c9db10>
self = <failure_demo.TestSpecialisedExplanations object at 0x17e3990>
def test_eq_long_text(self):
a = '1'*100 + 'a' + '2'*100
@@ -133,7 +132,7 @@ get on the terminal - we are working on that):
failure_demo.py:53: AssertionError
_________ TestSpecialisedExplanations.test_eq_long_text_multiline __________
self = <failure_demo.TestSpecialisedExplanations object at 0x2caf950>
self = <failure_demo.TestSpecialisedExplanations object at 0x17eee10>
def test_eq_long_text_multiline(self):
a = '1\n'*100 + 'a' + '2\n'*100
@@ -157,7 +156,7 @@ get on the terminal - we are working on that):
failure_demo.py:58: AssertionError
_________________ TestSpecialisedExplanations.test_eq_list _________________
self = <failure_demo.TestSpecialisedExplanations object at 0x2caf590>
self = <failure_demo.TestSpecialisedExplanations object at 0x17e3490>
def test_eq_list(self):
> assert [0, 1, 2] == [0, 1, 3]
@@ -167,7 +166,7 @@ get on the terminal - we are working on that):
failure_demo.py:61: AssertionError
______________ TestSpecialisedExplanations.test_eq_list_long _______________
self = <failure_demo.TestSpecialisedExplanations object at 0x2c9e310>
self = <failure_demo.TestSpecialisedExplanations object at 0x17e35d0>
def test_eq_list_long(self):
a = [0]*100 + [1] + [3]*100
@@ -179,7 +178,7 @@ get on the terminal - we are working on that):
failure_demo.py:66: AssertionError
_________________ TestSpecialisedExplanations.test_eq_dict _________________
self = <failure_demo.TestSpecialisedExplanations object at 0x2c9dc50>
self = <failure_demo.TestSpecialisedExplanations object at 0x17eef10>
def test_eq_dict(self):
> assert {'a': 0, 'b': 1} == {'a': 0, 'b': 2}
@@ -192,7 +191,7 @@ get on the terminal - we are working on that):
failure_demo.py:69: AssertionError
_________________ TestSpecialisedExplanations.test_eq_set __________________
self = <failure_demo.TestSpecialisedExplanations object at 0x2cafc10>
self = <failure_demo.TestSpecialisedExplanations object at 0x17f4d10>
def test_eq_set(self):
> assert set([0, 10, 11, 12]) == set([0, 20, 21])
@@ -208,7 +207,7 @@ get on the terminal - we are working on that):
failure_demo.py:72: AssertionError
_____________ TestSpecialisedExplanations.test_eq_longer_list ______________
self = <failure_demo.TestSpecialisedExplanations object at 0x2cba890>
self = <failure_demo.TestSpecialisedExplanations object at 0x17f4e10>
def test_eq_longer_list(self):
> assert [1,2] == [1,2,3]
@@ -218,7 +217,7 @@ get on the terminal - we are working on that):
failure_demo.py:75: AssertionError
_________________ TestSpecialisedExplanations.test_in_list _________________
self = <failure_demo.TestSpecialisedExplanations object at 0x2cba6d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x1801690>
def test_in_list(self):
> assert 1 in [0, 2, 3, 4, 5]
@@ -233,7 +232,7 @@ get on the terminal - we are working on that):
i = Foo()
> assert i.b == 2
E assert 1 == 2
E + where 1 = <failure_demo.Foo object at 0x2c9d750>.b
E + where 1 = <failure_demo.Foo object at 0x17f48d0>.b
failure_demo.py:85: AssertionError
_________________________ test_attribute_instance __________________________
@@ -243,8 +242,8 @@ get on the terminal - we are working on that):
b = 1
> assert Foo().b == 2
E assert 1 == 2
E + where 1 = <failure_demo.Foo object at 0x2cafdd0>.b
E + where <failure_demo.Foo object at 0x2cafdd0> = <class 'failure_demo.Foo'>()
E + where 1 = <failure_demo.Foo object at 0x17f4390>.b
E + where <failure_demo.Foo object at 0x17f4390> = <class 'failure_demo.Foo'>()
failure_demo.py:91: AssertionError
__________________________ test_attribute_failure __________________________
@@ -257,10 +256,10 @@ get on the terminal - we are working on that):
i = Foo()
> assert i.b == 2
failure_demo.py:100:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
failure_demo.py:100:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <failure_demo.Foo object at 0x2cba790>
self = <failure_demo.Foo object at 0x17ee790>
def _get_b(self):
> raise Exception('Failed to get attrib')
@@ -276,22 +275,22 @@ get on the terminal - we are working on that):
b = 2
> assert Foo().b == Bar().b
E assert 1 == 2
E + where 1 = <failure_demo.Foo object at 0x2cba210>.b
E + where <failure_demo.Foo object at 0x2cba210> = <class 'failure_demo.Foo'>()
E + and 2 = <failure_demo.Bar object at 0x2cba850>.b
E + where <failure_demo.Bar object at 0x2cba850> = <class 'failure_demo.Bar'>()
E + where 1 = <failure_demo.Foo object at 0x17eed10>.b
E + where <failure_demo.Foo object at 0x17eed10> = <class 'failure_demo.Foo'>()
E + and 2 = <failure_demo.Bar object at 0x17eead0>.b
E + where <failure_demo.Bar object at 0x17eead0> = <class 'failure_demo.Bar'>()
failure_demo.py:108: AssertionError
__________________________ TestRaises.test_raises __________________________
self = <failure_demo.TestRaises instance at 0x2cc2560>
self = <failure_demo.TestRaises instance at 0x1808170>
def test_raises(self):
s = 'qwe'
> raises(TypeError, "int(s)")
failure_demo.py:117:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
failure_demo.py:117:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> int(s)
E ValueError: invalid literal for int() with base 10: 'qwe'
@@ -299,7 +298,7 @@ get on the terminal - we are working on that):
<0-codegen /home/hpk/p/pytest/_pytest/python.py:819>:1: ValueError
______________________ TestRaises.test_raises_doesnt _______________________
self = <failure_demo.TestRaises instance at 0x2cb6bd8>
self = <failure_demo.TestRaises instance at 0x17fd908>
def test_raises_doesnt(self):
> raises(IOError, "int('3')")
@@ -308,7 +307,7 @@ get on the terminal - we are working on that):
failure_demo.py:120: Failed
__________________________ TestRaises.test_raise ___________________________
self = <failure_demo.TestRaises instance at 0x2cc4830>
self = <failure_demo.TestRaises instance at 0x1809440>
def test_raise(self):
> raise ValueError("demo error")
@@ -317,7 +316,7 @@ get on the terminal - we are working on that):
failure_demo.py:123: ValueError
________________________ TestRaises.test_tupleerror ________________________
self = <failure_demo.TestRaises instance at 0x2cc5560>
self = <failure_demo.TestRaises instance at 0x1806170>
def test_tupleerror(self):
> a,b = [1]
@@ -326,7 +325,7 @@ get on the terminal - we are working on that):
failure_demo.py:126: ValueError
______ TestRaises.test_reinterpret_fails_with_print_for_the_fun_of_it ______
self = <failure_demo.TestRaises instance at 0x2cc6248>
self = <failure_demo.TestRaises instance at 0x1806dd0>
def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
l = [1,2,3]
@@ -339,7 +338,7 @@ get on the terminal - we are working on that):
l is [1, 2, 3]
________________________ TestRaises.test_some_error ________________________
self = <failure_demo.TestRaises instance at 0x2cc6f38>
self = <failure_demo.TestRaises instance at 0x180ab48>
def test_some_error(self):
> if namenotexi:
@@ -357,8 +356,8 @@ get on the terminal - we are working on that):
py.std.sys.modules[name] = module
> module.foo()
failure_demo.py:149:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
failure_demo.py:149:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def foo():
> assert 1 == 0
@@ -367,7 +366,7 @@ get on the terminal - we are working on that):
<2-codegen 'abc-123' /home/hpk/p/pytest/doc/example/assertion/failure_demo.py:146>:2: AssertionError
____________________ TestMoreErrors.test_complex_error _____________________
self = <failure_demo.TestMoreErrors instance at 0x2cc4050>
self = <failure_demo.TestMoreErrors instance at 0x18081b8>
def test_complex_error(self):
def f():
@@ -376,16 +375,16 @@ get on the terminal - we are working on that):
return 43
> somefunc(f(), g())
failure_demo.py:159:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
failure_demo.py:159:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x = 44, y = 43
def somefunc(x,y):
> otherfunc(x,y)
failure_demo.py:8:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
failure_demo.py:8:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a = 44, b = 43
@@ -396,7 +395,7 @@ get on the terminal - we are working on that):
failure_demo.py:5: AssertionError
___________________ TestMoreErrors.test_z1_unpack_error ____________________
self = <failure_demo.TestMoreErrors instance at 0x2cc7ab8>
self = <failure_demo.TestMoreErrors instance at 0x180d6c8>
def test_z1_unpack_error(self):
l = []
@@ -406,7 +405,7 @@ get on the terminal - we are working on that):
failure_demo.py:163: ValueError
____________________ TestMoreErrors.test_z2_type_error _____________________
self = <failure_demo.TestMoreErrors instance at 0x2ccb8c0>
self = <failure_demo.TestMoreErrors instance at 0x18114d0>
def test_z2_type_error(self):
l = 3
@@ -416,19 +415,19 @@ get on the terminal - we are working on that):
failure_demo.py:167: TypeError
______________________ TestMoreErrors.test_startswith ______________________
self = <failure_demo.TestMoreErrors instance at 0x2ccd5f0>
self = <failure_demo.TestMoreErrors instance at 0x18d1200>
def test_startswith(self):
s = "123"
g = "456"
> assert s.startswith(g)
E assert <built-in method startswith of str object at 0x2c321b0>('456')
E + where <built-in method startswith of str object at 0x2c321b0> = '123'.startswith
E assert <built-in method startswith of str object at 0x177e240>('456')
E + where <built-in method startswith of str object at 0x177e240> = '123'.startswith
failure_demo.py:172: AssertionError
__________________ TestMoreErrors.test_startswith_nested ___________________
self = <failure_demo.TestMoreErrors instance at 0x2ccbc20>
self = <failure_demo.TestMoreErrors instance at 0x1811908>
def test_startswith_nested(self):
def f():
@@ -436,15 +435,15 @@ get on the terminal - we are working on that):
def g():
return "456"
> assert f().startswith(g())
E assert <built-in method startswith of str object at 0x2c321b0>('456')
E + where <built-in method startswith of str object at 0x2c321b0> = '123'.startswith
E + where '123' = <function f at 0x2c2d140>()
E + and '456' = <function g at 0x2cb00c8>()
E assert <built-in method startswith of str object at 0x177e240>('456')
E + where <built-in method startswith of str object at 0x177e240> = '123'.startswith
E + where '123' = <function f at 0x176f668>()
E + and '456' = <function g at 0x1800578>()
failure_demo.py:179: AssertionError
_____________________ TestMoreErrors.test_global_func ______________________
self = <failure_demo.TestMoreErrors instance at 0x2cb69e0>
self = <failure_demo.TestMoreErrors instance at 0x17fd9e0>
def test_global_func(self):
> assert isinstance(globf(42), float)
@@ -454,19 +453,19 @@ get on the terminal - we are working on that):
failure_demo.py:182: AssertionError
_______________________ TestMoreErrors.test_instance _______________________
self = <failure_demo.TestMoreErrors instance at 0x2cc6440>
self = <failure_demo.TestMoreErrors instance at 0x1806b90>
def test_instance(self):
self.x = 6*7
> assert self.x != 42
E assert 42 != 42
E + where 42 = 42
E + where 42 = <failure_demo.TestMoreErrors instance at 0x2cc6440>.x
E + where 42 = <failure_demo.TestMoreErrors instance at 0x1806b90>.x
failure_demo.py:186: AssertionError
_______________________ TestMoreErrors.test_compare ________________________
self = <failure_demo.TestMoreErrors instance at 0x2dcc200>
self = <failure_demo.TestMoreErrors instance at 0x18d1f38>
def test_compare(self):
> assert globf(10) < 5
@@ -476,7 +475,7 @@ get on the terminal - we are working on that):
failure_demo.py:189: AssertionError
_____________________ TestMoreErrors.test_try_finally ______________________
self = <failure_demo.TestMoreErrors instance at 0x2dce0e0>
self = <failure_demo.TestMoreErrors instance at 0x18d4cf8>
def test_try_finally(self):
x = 1

View File

@@ -7,6 +7,8 @@ basic patterns and examples
pass different values to a test function, depending on command line options
----------------------------------------------------------------------------
.. regendoc:wipe
Suppose we want to write a test that depends on a command line option.
Here is a basic pattern how to achieve this::
@@ -32,7 +34,8 @@ provide the ``cmdopt`` through a :ref:`function argument <funcarg>` factory::
Let's run this without supplying our new command line option::
$ py.test -q
$ py.test -q test_sample.py
collecting ... collected 1 items
F
================================= FAILURES =================================
_______________________________ test_answer ________________________________
@@ -55,6 +58,7 @@ Let's run this without supplying our new command line option::
And now with supplying a command line option::
$ py.test -q --cmdopt=type2
collecting ... collected 1 items
F
================================= FAILURES =================================
_______________________________ test_answer ________________________________
@@ -83,6 +87,8 @@ on real-life examples.
generating parameters combinations, depending on command line
----------------------------------------------------------------------------
.. regendoc:wipe
Let's say we want to execute a test with different parameters
and the parameter range shall be determined by a command
line argument. Let's first write a simple computation test::
@@ -112,13 +118,15 @@ Now we add a test configuration like this::
This means that we only run 2 tests if we do not pass ``--all``::
$ py.test -q test_compute.py
collecting ... collected 2 items
..
2 passed in 0.01 seconds
We run only two computations, so we see two dots.
let's run the full monty::
$ py.test -q --all test_compute.py
$ py.test -q --all
collecting ... collected 5 items
....F
================================= FAILURES =================================
_____________________________ test_compute[4] ______________________________
@@ -141,6 +149,8 @@ we'll get an error on the last one.
control skipping of tests according to command line option
--------------------------------------------------------------
.. regendoc:wipe
Here is a ``conftest.py`` file adding a ``--runslow`` command
line option to control skipping of ``slow`` marked tests::
@@ -171,32 +181,33 @@ We can now write a test module like this::
and when running it will see a skipped "slow" test::
$ py.test test_module.py -rs # "-rs" means report details on the little 's'
$ py.test -rs # "-rs" means report details on the little 's'
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev30
test path 1: test_module.py
platform linux2 -- Python 2.6.5 -- pytest-2.0.0
collecting ... collected 2 items
test_module.py .s
========================= short test summary info ==========================
SKIP [1] /tmp/doc-exec-104/conftest.py:9: need --runslow option to run
SKIP [1] /tmp/doc-exec-479/conftest.py:9: need --runslow option to run
=================== 1 passed, 1 skipped in 0.02 seconds ====================
Or run it including the ``slow`` marked test::
$ py.test test_module.py --runslow
$ py.test --runslow
=========================== test session starts ============================
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev30
test path 1: test_module.py
platform linux2 -- Python 2.6.5 -- pytest-2.0.0
collecting ... collected 2 items
test_module.py ..
========================= 2 passed in 0.01 seconds =========================
writing well integrated assertion helpers
--------------------------------------------------
.. regendoc:wipe
If you have a test helper function called from a test you can
use the ``pytest.fail`` marker to fail a test with a certain message.
The test support function will not show up in the traceback if you
@@ -218,7 +229,8 @@ of tracebacks: the ``checkconfig`` function will not be shown
unless the ``--fulltrace`` command line option is specified.
Let's run our little function::
$ py.test -q
$ py.test -q test_checkconfig.py
collecting ... collected 1 items
F
================================= FAILURES =================================
______________________________ test_something ______________________________
@@ -230,16 +242,17 @@ Let's run our little function::
test_checkconfig.py:8: Failed
1 failed in 0.02 seconds
Detect if running from within a py.test run
--------------------------------------------------------------
.. regendoc:wipe
Usually it is a bad idea to make application code
behave differently if called from a test. But if you
absolutely must find out if your application code is
running from a test you can do something like this::
# content of conftest.py in your testing directory
# content of conftest.py
def pytest_configure(config):
import sys