Skip to content

Commit

Permalink
probably the last major internal cleanup action: rename collection to
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
hpk42 committed Nov 7, 2010
1 parent 722e20c commit 6461295
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 143 deletions.
6 changes: 3 additions & 3 deletions doc/assert.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions doc/doctest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =============================
4 changes: 2 additions & 2 deletions doc/example/builtin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions doc/example/controlskip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ 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 ====================

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 ..
Expand Down
10 changes: 5 additions & 5 deletions doc/example/mysetup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.dev19
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev22
test path 1: test_sample.py

test_sample.py F

================================= FAILURES =================================
_______________________________ test_answer ________________________________

mysetup = <conftest.MySetup instance at 0x1cf6b90>
mysetup = <conftest.MySetup instance at 0x1ca5cf8>

def test_answer(mysetup):
app = mysetup.myapp()
Expand Down Expand Up @@ -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.

Expand Down
19 changes: 11 additions & 8 deletions doc/example/nonpython.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'>
1 change: 0 additions & 1 deletion doc/example/pythoncollection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'>
Expand Down
2 changes: 1 addition & 1 deletion doc/example/simple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 8 additions & 8 deletions doc/faq.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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":
Expand All @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions doc/funcargs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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]'>
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions doc/getting-started.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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

Expand Down Expand Up @@ -121,15 +121,15 @@ 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"
> assert hasattr(x, 'check')
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
Expand Down Expand Up @@ -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
Expand All @@ -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`.
Expand Down
14 changes: 7 additions & 7 deletions doc/mark.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =======================
Expand All @@ -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 ..

Expand Down
4 changes: 2 additions & 2 deletions doc/monkeypatch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =============================

Expand Down
4 changes: 2 additions & 2 deletions doc/plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6461295

Please sign in to comment.