probably the last major internal cleanup action: rename collection to
session which now is the root collection node. This means that session, collection and config objects have a more defined relationship (previously there was no way to get from a collection node or even from a runtest hook to the session object which was strange).
This commit is contained in:
+3
-3
@@ -21,7 +21,7 @@ assertion fails you will see the value of ``x``::
|
||||
|
||||
$ py.test test_assert1.py
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_assert1.py
|
||||
|
||||
test_assert1.py F
|
||||
@@ -35,7 +35,7 @@ assertion fails you will see the value of ``x``::
|
||||
E + where 3 = f()
|
||||
|
||||
test_assert1.py:5: AssertionError
|
||||
========================= 1 failed in 0.02 seconds =========================
|
||||
========================= 1 failed in 0.05 seconds =========================
|
||||
|
||||
Reporting details about the failing assertion is achieved by re-evaluating
|
||||
the assert expression and recording intermediate values.
|
||||
@@ -101,7 +101,7 @@ if you run this module::
|
||||
|
||||
$ py.test test_assert2.py
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_assert2.py
|
||||
|
||||
test_assert2.py F
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ then you can just invoke ``py.test`` without command line options::
|
||||
|
||||
$ py.test
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
test path 1: /tmp/doc-exec-400
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: /tmp/doc-exec-519
|
||||
|
||||
============================= in 0.00 seconds =============================
|
||||
|
||||
@@ -27,10 +27,10 @@ Let's run our little function::
|
||||
F
|
||||
================================= FAILURES =================================
|
||||
______________________________ test_something ______________________________
|
||||
|
||||
|
||||
def test_something():
|
||||
> checkconfig(42)
|
||||
E Failed: not configured: 42
|
||||
|
||||
|
||||
test_checkconfig.py:8: Failed
|
||||
1 failed in 0.02 seconds
|
||||
|
||||
@@ -36,12 +36,12 @@ and when running it will see a skipped "slow" test::
|
||||
|
||||
$ py.test test_module.py -rs # "-rs" means report on the little 's'
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_module.py
|
||||
|
||||
test_module.py .s
|
||||
========================= short test summary info ==========================
|
||||
SKIP [1] /tmp/doc-exec-435/conftest.py:9: need --runslow option to run
|
||||
SKIP [1] /tmp/doc-exec-557/conftest.py:9: need --runslow option to run
|
||||
|
||||
=================== 1 passed, 1 skipped in 0.02 seconds ====================
|
||||
|
||||
@@ -49,7 +49,7 @@ Or run it including the ``slow`` marked test::
|
||||
|
||||
$ py.test test_module.py --runslow
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_module.py
|
||||
|
||||
test_module.py ..
|
||||
|
||||
@@ -49,7 +49,7 @@ You can now run the test::
|
||||
|
||||
$ py.test test_sample.py
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_sample.py
|
||||
|
||||
test_sample.py F
|
||||
@@ -57,7 +57,7 @@ You can now run the test::
|
||||
================================= FAILURES =================================
|
||||
_______________________________ test_answer ________________________________
|
||||
|
||||
mysetup = <conftest.MySetup instance at 0x1cf6b90>
|
||||
mysetup = <conftest.MySetup instance at 0x1ca5cf8>
|
||||
|
||||
def test_answer(mysetup):
|
||||
app = mysetup.myapp()
|
||||
@@ -122,14 +122,14 @@ Running it yields::
|
||||
|
||||
$ py.test test_ssh.py -rs
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_ssh.py
|
||||
|
||||
test_ssh.py s
|
||||
========================= short test summary info ==========================
|
||||
SKIP [1] /tmp/doc-exec-438/conftest.py:22: specify ssh host with --ssh
|
||||
SKIP [1] /tmp/doc-exec-560/conftest.py:22: specify ssh host with --ssh
|
||||
|
||||
======================== 1 skipped in 0.02 seconds =========================
|
||||
======================== 1 skipped in 0.03 seconds =========================
|
||||
|
||||
If you specify a command line option like ``py.test --ssh=python.org`` the test will execute as expected.
|
||||
|
||||
|
||||
@@ -27,17 +27,19 @@ now execute the test specification::
|
||||
|
||||
nonpython $ py.test test_simple.yml
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_simple.yml
|
||||
|
||||
|
||||
test_simple.yml .F
|
||||
|
||||
|
||||
================================= FAILURES =================================
|
||||
______________________________ usecase: hello ______________________________
|
||||
usecase execution failed
|
||||
spec failed: 'some': 'other'
|
||||
no further details known at this point.
|
||||
==================== 1 failed, 1 passed in 0.42 seconds ====================
|
||||
========================= short test summary info ==========================
|
||||
FAIL test_simple.yml::hello
|
||||
==================== 1 failed, 1 passed in 0.43 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
|
||||
@@ -56,24 +58,25 @@ reporting in ``verbose`` mode::
|
||||
|
||||
nonpython $ py.test -v
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19 -- /home/hpk/venv/0/bin/python
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22 -- /home/hpk/venv/0/bin/python
|
||||
test path 1: /home/hpk/p/pytest/doc/example/nonpython
|
||||
|
||||
|
||||
test_simple.yml <- test_simple.yml:1: usecase: ok PASSED
|
||||
test_simple.yml <- test_simple.yml:1: usecase: hello FAILED
|
||||
|
||||
|
||||
================================= FAILURES =================================
|
||||
______________________________ usecase: hello ______________________________
|
||||
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.07 seconds ====================
|
||||
|
||||
While developing your custom test collection and execution it's also
|
||||
interesting to just look at the collection tree::
|
||||
|
||||
nonpython $ py.test --collectonly
|
||||
<Collection 'nonpython'>
|
||||
<YamlFile 'test_simple.yml'>
|
||||
<YamlItem 'ok'>
|
||||
<YamlItem 'hello'>
|
||||
|
||||
@@ -31,7 +31,6 @@ finding out what is collected
|
||||
You can always peek at the collection tree without running tests like this::
|
||||
|
||||
. $ py.test --collectonly collectonly.py
|
||||
<Collection 'example'>
|
||||
<Module 'collectonly.py'>
|
||||
<Function 'test_function'>
|
||||
<Class 'TestClass'>
|
||||
|
||||
@@ -130,7 +130,7 @@ let's run the full monty::
|
||||
E assert 4 < 4
|
||||
|
||||
test_compute.py:3: AssertionError
|
||||
1 failed, 4 passed in 0.02 seconds
|
||||
1 failed, 4 passed in 0.03 seconds
|
||||
|
||||
As expected when running the full range of ``param1`` values
|
||||
we'll get an error on the last one.
|
||||
|
||||
+8
-8
@@ -12,11 +12,11 @@ On naming, nosetests, licensing and magic XXX
|
||||
Why a ``py.test`` instead of a ``pytest`` command?
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Some historic, some practical reasons: ``py.test`` used to be part of
|
||||
Some historic, some practical reasons: ``py.test`` used to be part of
|
||||
the ``py`` package which provided several developer utitilities,
|
||||
all starting with ``py.<TAB>``, providing nice TAB-completion. If
|
||||
you install ``pip install pycmd`` you get these tools from a separate
|
||||
package. These days the command line tool could be ``pytest``
|
||||
package. These days the command line tool could be ``pytest``
|
||||
but then many people have gotten used to the old name and there
|
||||
also is another tool with this same which would lead to some clashes.
|
||||
|
||||
@@ -37,11 +37,11 @@ What's this "magic" with py.test?
|
||||
|
||||
Around 2007 (version ``0.8``) some several people claimed that py.test
|
||||
was using too much "magic". It has been refactored a lot. It is today
|
||||
probably one of the smallest, most universally runnable and most
|
||||
customizable testing frameworks for Python. It remains true
|
||||
that ``py.test`` uses metaprogramming techniques, i.e. it views
|
||||
test code similar to how compilers view programs, using a
|
||||
somewhat abstract internal model.
|
||||
probably one of the smallest, most universally runnable and most
|
||||
customizable testing frameworks for Python. It remains true
|
||||
that ``py.test`` uses metaprogramming techniques, i.e. it views
|
||||
test code similar to how compilers view programs, using a
|
||||
somewhat abstract internal model.
|
||||
|
||||
It's also true that the no-boilerplate testing is implemented by making
|
||||
use of the Python assert statement through "re-interpretation":
|
||||
@@ -64,7 +64,7 @@ function arguments, parametrized tests and setup
|
||||
Is using funcarg- versus xUnit setup a style question?
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
For simple applications and for people experienced with nose_ or
|
||||
For simple applications and for people experienced with nose_ or
|
||||
unittest-style test setup using `xUnit style setup`_
|
||||
feels natural. For larger test suites, parametrized testing
|
||||
or setup of complex test resources using funcargs_ is recommended.
|
||||
|
||||
+3
-4
@@ -34,7 +34,7 @@ Running the test looks like this::
|
||||
|
||||
$ py.test test_simplefactory.py
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_simplefactory.py
|
||||
|
||||
test_simplefactory.py F
|
||||
@@ -136,7 +136,7 @@ Running this::
|
||||
|
||||
$ py.test test_example.py
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_example.py
|
||||
|
||||
test_example.py .........F
|
||||
@@ -158,7 +158,6 @@ the test collection phase which is separate from the actual test running.
|
||||
Let's just look at what is collected::
|
||||
|
||||
$ py.test --collectonly test_example.py
|
||||
<Collection 'doc-exec-403'>
|
||||
<Module 'test_example.py'>
|
||||
<Function 'test_func[0]'>
|
||||
<Function 'test_func[1]'>
|
||||
@@ -175,7 +174,7 @@ If you want to select only the run with the value ``7`` you could do::
|
||||
|
||||
$ py.test -v -k 7 test_example.py # or -k test_func[7]
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19 -- /home/hpk/venv/0/bin/python
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22 -- /home/hpk/venv/0/bin/python
|
||||
test path 1: test_example.py
|
||||
|
||||
test_example.py <- test_example.py:6: test_func[7] PASSED
|
||||
|
||||
@@ -14,7 +14,7 @@ Installation options::
|
||||
To check your installation has installed the correct version::
|
||||
|
||||
$ py.test --version
|
||||
This is py.test version 2.0.0.dev19, imported from /home/hpk/p/pytest/pytest
|
||||
This is py.test version 2.0.0.dev22, imported from /home/hpk/p/pytest/pytest
|
||||
|
||||
If you get an error checkout :ref:`installation issues`.
|
||||
|
||||
@@ -34,8 +34,8 @@ That's it. You can execute the test function now::
|
||||
|
||||
$ py.test
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
test path 1: /tmp/doc-exec-404
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: /tmp/doc-exec-523
|
||||
|
||||
test_sample.py F
|
||||
|
||||
@@ -121,7 +121,7 @@ run the module by passing its filename::
|
||||
================================= FAILURES =================================
|
||||
____________________________ TestClass.test_two ____________________________
|
||||
|
||||
self = <test_class.TestClass instance at 0x2c2c560>
|
||||
self = <test_class.TestClass instance at 0x254f6c8>
|
||||
|
||||
def test_two(self):
|
||||
x = "hello"
|
||||
@@ -129,7 +129,7 @@ run the module by passing its filename::
|
||||
E assert hasattr('hello', 'check')
|
||||
|
||||
test_class.py:8: AssertionError
|
||||
1 failed, 1 passed in 0.02 seconds
|
||||
1 failed, 1 passed in 0.03 seconds
|
||||
|
||||
The first test passed, the second failed. Again we can easily see
|
||||
the intermediate values used in the assertion, helping us to
|
||||
@@ -157,7 +157,7 @@ before performing the test function call. Let's just run it::
|
||||
================================= FAILURES =================================
|
||||
_____________________________ test_needsfiles ______________________________
|
||||
|
||||
tmpdir = local('/tmp/pytest-240/test_needsfiles0')
|
||||
tmpdir = local('/tmp/pytest-446/test_needsfiles0')
|
||||
|
||||
def test_needsfiles(tmpdir):
|
||||
print tmpdir
|
||||
@@ -166,8 +166,8 @@ before performing the test function call. Let's just run it::
|
||||
|
||||
test_tmpdir.py:3: AssertionError
|
||||
----------------------------- Captured stdout ------------------------------
|
||||
/tmp/pytest-240/test_needsfiles0
|
||||
1 failed in 0.04 seconds
|
||||
/tmp/pytest-446/test_needsfiles0
|
||||
1 failed in 0.07 seconds
|
||||
|
||||
Before the test runs, a unique-per-test-invocation temporary directory
|
||||
was created. More info at :ref:`tmpdir handling`.
|
||||
|
||||
+7
-7
@@ -88,20 +88,20 @@ You can use the ``-k`` command line option to select tests::
|
||||
|
||||
$ py.test -k webtest # running with the above defined examples yields
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
test path 1: /tmp/doc-exec-407
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: /tmp/doc-exec-527
|
||||
|
||||
test_mark.py ..
|
||||
test_mark_classlevel.py ..
|
||||
|
||||
========================= 4 passed in 0.01 seconds =========================
|
||||
========================= 4 passed in 0.02 seconds =========================
|
||||
|
||||
And you can also run all tests except the ones that match the keyword::
|
||||
|
||||
$ py.test -k-webtest
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
test path 1: /tmp/doc-exec-407
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: /tmp/doc-exec-527
|
||||
|
||||
===================== 4 tests deselected by '-webtest' =====================
|
||||
======================= 4 deselected in 0.01 seconds =======================
|
||||
@@ -110,8 +110,8 @@ Or to only select the class::
|
||||
|
||||
$ py.test -kTestClass
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
test path 1: /tmp/doc-exec-407
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: /tmp/doc-exec-527
|
||||
|
||||
test_mark_classlevel.py ..
|
||||
|
||||
|
||||
+2
-2
@@ -39,8 +39,8 @@ will be undone.
|
||||
.. background check:
|
||||
$ py.test
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
test path 1: /tmp/doc-exec-408
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: /tmp/doc-exec-528
|
||||
|
||||
============================= in 0.00 seconds =============================
|
||||
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ conftest.py: local per-directory plugins
|
||||
--------------------------------------------------------------
|
||||
|
||||
local ``conftest.py`` plugins contain directory-specific hook
|
||||
implementations. Collection and test running activities will
|
||||
implementations. Session and test running activities will
|
||||
invoke all hooks defined in "higher up" ``conftest.py`` files.
|
||||
Example: Assume the following layout and content of files::
|
||||
|
||||
@@ -268,7 +268,7 @@ you can use the following hook:
|
||||
reporting hooks
|
||||
------------------------------
|
||||
|
||||
Collection related reporting hooks:
|
||||
Session related reporting hooks:
|
||||
|
||||
.. autofunction: pytest_collectstart
|
||||
.. autofunction: pytest_itemcollected
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ Running this would result in a passed test except for the last
|
||||
|
||||
$ py.test test_tmpdir.py
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_tmpdir.py
|
||||
|
||||
test_tmpdir.py F
|
||||
@@ -36,7 +36,7 @@ Running this would result in a passed test except for the last
|
||||
================================= FAILURES =================================
|
||||
_____________________________ test_create_file _____________________________
|
||||
|
||||
tmpdir = local('/tmp/pytest-243/test_create_file0')
|
||||
tmpdir = local('/tmp/pytest-447/test_create_file0')
|
||||
|
||||
def test_create_file(tmpdir):
|
||||
p = tmpdir.mkdir("sub").join("hello.txt")
|
||||
@@ -47,7 +47,7 @@ Running this would result in a passed test except for the last
|
||||
E assert 0
|
||||
|
||||
test_tmpdir.py:7: AssertionError
|
||||
========================= 1 failed in 0.04 seconds =========================
|
||||
========================= 1 failed in 0.15 seconds =========================
|
||||
|
||||
.. _`base temporary directory`:
|
||||
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ Running it yields::
|
||||
|
||||
$ py.test test_unittest.py
|
||||
=========================== test session starts ============================
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev19
|
||||
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
|
||||
test path 1: test_unittest.py
|
||||
|
||||
test_unittest.py F
|
||||
@@ -56,7 +56,7 @@ Running it yields::
|
||||
/usr/lib/python2.6/unittest.py:350: AssertionError
|
||||
----------------------------- Captured stdout ------------------------------
|
||||
hello
|
||||
========================= 1 failed in 0.02 seconds =========================
|
||||
========================= 1 failed in 0.12 seconds =========================
|
||||
|
||||
.. _`unittest.py style`: http://docs.python.org/library/unittest.html
|
||||
|
||||
|
||||
@@ -175,5 +175,4 @@ Running it will exit quickly::
|
||||
$ python myinvoke.py
|
||||
ERROR: hi from our plugin
|
||||
|
||||
|
||||
.. include:: links.inc
|
||||
|
||||
Reference in New Issue
Block a user