isolate test example run

This commit is contained in:
holger krekel 2011-11-18 21:26:38 +00:00
parent 679d72eedf
commit cf02fb60c1
2 changed files with 24 additions and 28 deletions

View File

@ -40,7 +40,7 @@ clean:
-rm -rf $(BUILDDIR)/*
install: html
@rsync -avz _build/html/ pytest.org:/www/pytest.org/2.2.0
-avz _build/html/ pytest.org:/www/pytest.org/latest
installpdf: latexpdf
@scp $(BUILDDIR)/latex/pytest.pdf pytest.org:/www/pytest.org/latest

View File

@ -25,26 +25,26 @@ You can "mark" a test function with custom metadata like this::
You can then restrict a test run to only run tests marked with ``webtest``::
$ py.test -v -m webtest
=========================== test session starts ============================
============================= test session starts ==============================
platform darwin -- Python 2.7.1 -- pytest-2.2.0 -- /Users/hpk/venv/1/bin/python
collecting ... collected 2 items
test_server.py:3: test_send_http PASSED
=================== 1 tests deselected by "-m 'webtest'" ===================
================== 1 passed, 1 deselected in 0.01 seconds ==================
===================== 1 tests deselected by "-m 'webtest'" =====================
==================== 1 passed, 1 deselected in 0.01 seconds ====================
Or the inverse, running all tests except the webtest ones::
$ py.test -v -m "not webtest"
=========================== test session starts ============================
============================= test session starts ==============================
platform darwin -- Python 2.7.1 -- pytest-2.2.0 -- /Users/hpk/venv/1/bin/python
collecting ... collected 2 items
test_server.py:6: test_something_quick PASSED
================= 1 tests deselected by "-m 'not webtest'" =================
================== 1 passed, 1 deselected in 0.01 seconds ==================
=================== 1 tests deselected by "-m 'not webtest'" ===================
==================== 1 passed, 1 deselected in 0.02 seconds ====================
Registering markers
-------------------------------------
@ -140,45 +140,47 @@ Using ``-k TEXT`` to select tests
You can use the ``-k`` command line option to only run tests with names that match the given argument::
$ py.test -k send_http # running with the above defined examples
=========================== test session starts ============================
============================= test session starts ==============================
platform darwin -- Python 2.7.1 -- pytest-2.2.0
collecting ... collected 4 items
test_server.py .
=================== 3 tests deselected by '-ksend_http' ====================
================== 1 passed, 3 deselected in 0.02 seconds ==================
===================== 3 tests deselected by '-ksend_http' ======================
==================== 1 passed, 3 deselected in 0.02 seconds ====================
And you can also run all tests except the ones that match the keyword::
$ py.test -k-send_http
=========================== test session starts ============================
============================= test session starts ==============================
platform darwin -- Python 2.7.1 -- pytest-2.2.0
collecting ... collected 4 items
test_mark_classlevel.py ..
test_server.py .
=================== 1 tests deselected by '-k-send_http' ===================
================== 3 passed, 1 deselected in 0.03 seconds ==================
===================== 1 tests deselected by '-k-send_http' =====================
==================== 3 passed, 1 deselected in 0.03 seconds ====================
Or to only select the class::
$ py.test -kTestClass
=========================== test session starts ============================
============================= test session starts ==============================
platform darwin -- Python 2.7.1 -- pytest-2.2.0
collecting ... collected 4 items
test_mark_classlevel.py ..
=================== 2 tests deselected by '-kTestClass' ====================
================== 2 passed, 2 deselected in 0.02 seconds ==================
===================== 2 tests deselected by '-kTestClass' ======================
==================== 2 passed, 2 deselected in 0.02 seconds ====================
.. _`adding a custom marker from a plugin`:
custom marker and command line option to control test runs
----------------------------------------------------------
.. regendoc:wipe
Plugins can provide custom markers and implement specific behaviour
based on it. This is a self-contained example which adds a command
line option and a parametrized test function marker to run tests
@ -218,34 +220,28 @@ and an example invocations specifying a different environment than what
the test needs::
$ py.test -E stage2
=========================== test session starts ============================
============================= test session starts ==============================
platform darwin -- Python 2.7.1 -- pytest-2.2.0
collecting ... collected 5 items
collecting ... collected 1 items
test_mark_classlevel.py ..
test_server.py ..
test_someenv.py s
=================== 4 passed, 1 skipped in 0.04 seconds ====================
========================== 1 skipped in 0.02 seconds ===========================
and here is one that specifies exactly the environment needed::
$ py.test -E stage1
=========================== test session starts ============================
============================= test session starts ==============================
platform darwin -- Python 2.7.1 -- pytest-2.2.0
collecting ... collected 5 items
collecting ... collected 1 items
test_mark_classlevel.py ..
test_server.py ..
test_someenv.py .
========================= 5 passed in 0.04 seconds =========================
=========================== 1 passed in 0.02 seconds ===========================
The ``--markers`` option always gives you a list of available markers::
$ py.test --markers
@pytest.mark.webtest: mark a test as a webtest.
@pytest.mark.env(name): mark test to run only on named environment
@pytest.mark.skipif(*conditions): skip the given test function if evaluation of all conditions has a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform.