Compare commits

...

365 Commits
2.5.1 ... 2.6.2

Author SHA1 Message Date
holger krekel
7dad3cb157 prepare 2.6.2, release announcement, also add HOWTORELEASE.rst 2014-09-05 13:13:23 +02:00
holger krekel
745737e337 strike python2.5 from test code cc @flub 2014-09-05 09:50:40 +02:00
Floris Bruynooghe
eae1055fb0 Merged in nocoddemus/pytest/cx_freeze-support (pull request #189) 2014-09-03 21:55:46 +01:00
holger krekel
2e1c36bbb6 merged in flub/pytest (PR #195) 2014-09-02 12:33:19 +02:00
holger krekel
e3cea41dcd fix issue572 - python3 compat of tmpdir example in docs. 2014-09-02 12:20:16 +02:00
Benjamin Peterson
c0f091d540 remove debugging turd 2014-09-01 16:51:44 -04:00
Benjamin Peterson
d4cd1aad8e improvements to rewrite cache invalidation
- stat the source path before it is read.
- Validate the source size in addition to mtime.
2014-09-01 16:51:27 -04:00
Floris Bruynooghe
39a297afe6 Improve test by also matching expected output 2014-08-30 21:57:01 +01:00
Floris Bruynooghe
068548f7a9 Merged in flub/pytest (pull request #196) 2014-08-27 21:00:24 +01:00
Bruno Oliveira
0c163ce624 Updating plugins_index
Also fixed duplicated links when repository is not github or
bitbucket
2014-08-26 20:38:19 -03:00
Bruno Oliveira
fc95877622 Added changelog entry for freeze_includes()
--HG--
branch : cx_freeze-support
2014-08-23 10:10:32 -03:00
Bruno Oliveira
03b694a1d0 merging with default
--HG--
branch : cx_freeze-support
2014-08-23 10:05:40 -03:00
Floris Bruynooghe
79c2a47985 Improve the docstring further 2014-08-23 12:10:16 +02:00
Floris Bruynooghe
9289d77a80 Mention why no universal wheel in changelog
Fixes issue566.
2014-08-22 20:22:51 +02:00
Floris Bruynooghe
2eee2d0099 Merged in sontek/pytest/fix_universal (pull request #198)
Removed marking pytest as universal, py26 and py27 are not compatible.
2014-08-22 20:16:17 +02:00
sontek@gmail.com
0ea46e6aef Removed marking pytest as universal, py26 and py27 are not compatible.
--HG--
branch : fix_universal
2014-08-21 12:47:53 -07:00
Floris Bruynooghe
b0ac3581dd Mention doc fix in changelog 2014-08-19 21:00:46 +02:00
Floris Bruynooghe
e7ed45a5d4 Explain why this is important 2014-08-19 20:50:25 +02:00
Thomas Weißschuh
7cf859085e [doc] fix requests monkeypatch example 2014-08-18 19:44:34 +00:00
Floris Bruynooghe
424479cf0f Escape newlines in repr for assertion rewriting
The assertion formatting mini-language depends on newlines being
escaped.  Unfortunately if the repr of an object contained
newlines the rewriting module did not escape those, which is now
fixed.

Fixes issue453.
2014-08-18 20:07:38 +02:00
Floris Bruynooghe
98dcd764bc Depend on newer version of py
This fixes issue560, a test for which is included here as well.
2014-08-14 23:23:04 +01:00
Bruno Oliveira
ccd67733fb standard lib modules no longer required in freeze_includes() and updated docs
--HG--
branch : cx_freeze-support
2014-08-11 20:20:41 -03:00
Bruno Oliveira
5873ca5146 Merging with default
--HG--
branch : cx_freeze-support
2014-08-11 20:07:11 -03:00
Bruno Oliveira
d2903507d8 Moved freeze_includes() to genscript
--HG--
branch : cx_freeze-support
2014-08-11 20:03:14 -03:00
holger krekel
9232b88df3 actually regen fixture docs with python3.4 instead of python2.7 (doh) 2014-08-08 15:25:16 +02:00
holger krekel
e98f77037e fix issue561 example adapted to python3. 2014-08-08 15:20:37 +02:00
holger krekel
672e42e558 fix doc config for latex 2014-08-07 23:05:02 +02:00
holger krekel
36d7df4542 Added tag 2.6.1 for changeset a4f9639702ba 2014-08-07 22:55:17 +02:00
holger krekel
e5eaf02e19 finalize pytest-2.6.1 release, regen docs 2014-08-07 21:41:51 +02:00
holger krekel
1d7b574b31 fix issue555: just add "errors" attribute to internal Capture stream. 2014-08-07 11:05:42 +02:00
holger krekel
d16fdb378c merge PR192, streamline a bit. 2014-08-07 10:42:23 +02:00
Bruno Oliveira
cc092afd3b updated CHANGELOG and trace error message as requested in review
fixes issue #437

--HG--
branch : assertionrewrite-currupted-pyc
2014-08-04 20:38:50 -03:00
Bruno Oliveira
fd4485a540 Fixed assertionrewrite._read_pyc to handle corrupted pyc files properly
This seems to be the cause for issues #437 and #301.

--HG--
branch : assertionrewrite-currupted-pyc
2014-08-02 18:01:28 -03:00
Floris Bruynooghe
3b8779ad17 Mention change in -v output in changelog 2014-08-01 23:11:25 +01:00
Floris Bruynooghe
3e875178ad Merge default 2014-08-01 23:06:24 +01:00
holger krekel
97b671057d put some imports back to function-level and streamline py2/py3 compat in one place 2014-08-01 10:12:53 +02:00
holger krekel
d6fc489b2b Backed out changeset e57017ad86ce -- logging should not be imported 2014-08-01 08:13:44 +02:00
Floris Bruynooghe
4e8438afc8 Simply show the node ID for verbose output
This strips the line number, /@\d/, from the verbose output so it is
directly the node ID of the test.  This in turn means no special logic
for accepting the line number as part of the node ID is needed when
parsing the command line.
2014-08-01 00:29:35 +01:00
Bruno Oliveira
b1f8038abf Minor fixed in test_capture
This test failed only in py34. We don't import logging directly,
but it seems that one of the standard modules that are now
globally imported started including this on py34.

Just removed the assert as it doesn't seem central to the
test's objective.
2014-07-31 19:52:08 -03:00
Bruno Oliveira
5603a0cd4b Removing py.std usage from _pytest 2014-07-31 19:13:40 -03:00
Bruno Oliveira
3c649cf91d guarding scripts with __main__ and doc changes
tox-flakes environment tries to import the modules for
checking, and that may fail because of its dependencies

--HG--
branch : cx_freeze-support
2014-07-30 22:28:03 -03:00
Bruno Oliveira
82d573e391 fixed line endings for test_doctest.txt
--HG--
branch : cx_freeze-support
2014-07-30 21:57:19 -03:00
Bruno Oliveira
b7b96b24d8 Docs about cx_freeze support and minor adjustments
--HG--
branch : cx_freeze-support
2014-07-30 21:50:00 -03:00
Bruno Oliveira
990e7bf3b9 first implementation and tox environment for cx-freeze support
--HG--
branch : cx_freeze-support
2014-07-30 19:16:51 -03:00
holger krekel
bcdc3d0154 reorder talks, more talks from pelme and others 2014-07-29 15:06:37 +02:00
holger krekel
faea7e1407 add flub and pelme talks at EuroPython2014, remove one past training note 2014-07-29 15:00:45 +02:00
holger krekel
7c701948d5 Merged in nicoddemus/pytest/cx_freeze-docs (pull request #188)
Documentation example on how to integrate pytest and cx_freeze
2014-07-29 12:43:04 +02:00
Bruno Oliveira
899b804ec1 Improved the text a little
--HG--
branch : cx_freeze-docs
2014-07-28 22:46:57 -03:00
Bruno Oliveira
66bd4e485a Adding blurb about using pytest runner and cx_freeze
--HG--
branch : cx_freeze-docs
2014-07-28 22:40:23 -03:00
Anatoly Bubenkov
8ff8dd3ae9 Merged in fix_initial_parsing (pull request #186)
Fix issue544 and fix another issue with parsing ``::``
2014-07-28 14:16:02 +02:00
holger krekel
0d17dc1e19 add a comment for why we only consider .py files when removing @
--HG--
branch : fix_initial_parsing
2014-07-28 13:56:10 +02:00
holger krekel
83e0b52294 speedup @ replacement for the massive lists from pytest-bdd :)
--HG--
branch : fix_initial_parsing
2014-07-28 13:53:53 +02:00
holger krekel
1265612465 fix issue547 2.6 regression: capsys/capfd now work again when output capturing ("-s") is disabled. 2014-07-28 13:17:37 +02:00
holger krekel
40eed363e8 fix issue544 by only removing "@NUM" at the end of a part (parts are
separated by "::") and if the part has an .py extension.

--HG--
branch : fix_initial_parsing
2014-07-28 12:07:15 +02:00
holger krekel
5ccd3f2fc5 fix conftest detection if commandline arguments contain "::" syntax
--HG--
branch : fix_initial_parsing
2014-07-28 11:48:37 +02:00
holger krekel
ba878c6d9d add changelog entry and refactor unittest.mock.patch fix a bit 2014-07-28 10:34:01 +02:00
holger krekel
8792261df1 Merged in ticosax/pytest/mock-unittest-252 (pull request #184)
Injection of fixture doesn't work when decorated with unittest.mock.patch
2014-07-28 10:31:31 +02:00
holger krekel
c2ed29070a address issue170 by merging David Mohr's PR on adding "raises" as an optional
argument to pytest.mark.xfail.
2014-07-28 09:59:22 +02:00
holger krekel
38104dfc92 Merged in squisher/pytest/xfail-cause (pull request #183)
Add mark.xfail argument raises so that unexpected exceptions show up as test failures.
2014-07-28 09:55:02 +02:00
Nicolas Delaby
2e55c4ba61 unittest.mock from stdlib should come last
--HG--
branch : mock-unittest-252
2014-07-27 12:11:39 +02:00
Nicolas Delaby
e6ad6e02d2 Handle also unittest.mock
Move handling in dedicated function to isolate its logic

--HG--
branch : mock-unittest-252
2014-07-27 10:43:50 +02:00
david@mcbf.net
d08c4ce0ad Tiny example update for clarification
--HG--
branch : xfail-cause
2014-07-26 18:24:55 +02:00
david@mcbf.net
309e3d38a0 Directly pass multiple parameters with mark.parametrize()
--HG--
branch : xfail-cause
2014-07-26 18:19:27 +02:00
david@mcbf.net
91e2b23258 Update documentation
--HG--
branch : xfail-cause
2014-07-26 18:10:32 +02:00
david@mcbf.net
6a4492a22d isinstance() on exception value instead of comparing types, consolidate tests
--HG--
branch : xfail-cause
2014-07-26 17:46:50 +02:00
Nicolas Delaby
0dd378da30 Injection of fixture doesn't work when decorated with unittest.mock.patch
This is a continuation of #182

--HG--
branch : mock-unittest-252
2014-07-26 17:26:18 +02:00
david@mcbf.net
7b273b8577 Add mark.xfail argument raises so that unexpected exceptions show up as test failures.
--HG--
branch : xfail-cause
2014-07-26 15:11:05 +02:00
holger krekel
d98521b0d9 Added tag 2.6.0 for changeset 88af949b9611 2014-07-20 13:15:44 +02:00
holger krekel
52011e84d3 merge 2014-07-20 13:15:21 +02:00
holger krekel
de583ed7a3 some notes about upcoming trainings 2014-07-20 13:07:38 +02:00
holger krekel
f8480caae4 Added tag 2.6.0 for changeset 60725b17a9d1 2014-07-20 13:03:11 +02:00
holger krekel
47d9e6ca1f fix release announce 2014-07-20 11:07:18 +02:00
Bruno Oliveira
6f0a33dfdc Updating plugins_index 2014-07-18 21:10:50 -03:00
Floris Bruynooghe
1641d00cb1 Merge default 2014-07-18 01:34:08 +01:00
Floris Bruynooghe
2d7a32f7ea Add test case for using different modules 2014-07-18 01:30:29 +01:00
holger krekel
06acbb9f5e bump doc version 2014-07-17 17:22:44 +02:00
holger krekel
7b630d9080 mention next open trainings at EP2014 and in Freiburg in November 2014 2014-07-17 17:21:45 +02:00
holger krekel
98de64badc regen docs for pytest-2.6 2014-07-17 16:55:24 +02:00
holger krekel
1e241e1f2a mention py34 compatibility 2014-07-17 16:49:10 +02:00
holger krekel
ff2c18fedb bump version, preliminary announcement 2014-07-17 16:38:54 +02:00
holger krekel
bf64a800d6 pytest depends on the freshly released 1.4.22 to function properly 2014-07-17 10:55:52 +02:00
Jurko Gospodnetić
efc57391eb remove extra parentheses - stylistic code change 2014-07-17 08:35:36 +02:00
Benjamin Peterson
dc65aa1fea avoid importing old assertion interpretation code by default (fixes #537) 2014-07-16 17:21:18 -07:00
holger krekel
80ad3fb8ed Merged in wooparadog/pytest (pull request #163)
Also replace `report.longrepr` with `bin_xml_escape`ed skipreason
2014-07-15 22:17:15 +02:00
holger krekel
bc7110931a Merged in alex_gaynor/pytest/alex_gaynor/marked-pytest-as-being-a-universal-wheel-1405267754279 (pull request #179)
Marked pytest as being a universal wheel.
2014-07-15 11:26:08 +02:00
holger krekel
8c508612ec with pypy this tests leaks one FD but it's probably a residual effect of the testing machinery and Pypy's lazy GC. 2014-07-14 09:17:04 +02:00
Alex Gaynor
b7d046527e Marked pytest as being a universal wheel.
--HG--
branch : alex_gaynor/marked-pytest-as-being-a-universal-wheel-1405267754279
2014-07-13 16:09:24 +00:00
holger krekel
42804c52e8 Merged in bmcorser/pytest-1/bmcorser/scratching-an-itch-love-pytest-1404943207227 (pull request #178)
Scratching an itch. Love py.test!
2014-07-10 09:00:24 +02:00
bmcorser
d88a3712c5 Scratching an itch. Love py.test!
--HG--
branch : bmcorser/scratching-an-itch-love-pytest-1404943207227
2014-07-09 22:00:24 +00:00
Bruno Oliveira
abfedd692e Updating plugins_index 2014-07-08 20:08:19 -03:00
holger krekel
d0b048c86d Merged in msabramo/pytest/norecursedirs_add_star_dot_egg (pull request #177)
Add *.egg to default for norecursedirs
2014-07-03 16:51:17 +02:00
Marc Abramowitz
b6f069f4c3 Add *.egg to default for norecursedirs
--HG--
branch : norecursedirs_add_star_dot_egg
2014-07-03 07:49:03 -07:00
holger krekel
edc2e5ab82 Merged in msabramo/pytest/fix_norecursedirs_doc_typos (pull request #176)
doc/en/customize.txt: Fix norecursedirs typo
2014-07-03 16:47:58 +02:00
Marc Abramowitz
6da9a087f8 doc/en/customize.txt: Fix norecursedirs typo
and update documented default to match current default.

--HG--
branch : fix_norecursedirs_doc_typos
2014-07-03 07:36:07 -07:00
holger krekel
e19462d581 fix ordering of import line of last commit 2014-07-03 13:20:51 +02:00
holger krekel
a811fabb43 avoid importing "py.test" (an old alias module for "pytest") 2014-07-03 12:58:12 +02:00
holger krekel
07e76cbef2 fix issue364: shorten and enhance tracebacks representation by default.
The new "--tb=auto" option (default) will only display long tracebacks
for the first and last entry.  You can get the old behaviour of printing
all entries as long entries with "--tb=long".  Also short entries by
default are now printed very similarly to "--tb=native" ones.
2014-06-29 13:32:53 +02:00
holger krekel
76d5c9e4f4 Merged in c_henz/pytest/explicit-ini-filename (pull request #175)
Implement the "-c" command line switch that allows to explicitly specifiy the config file to load.
2014-06-29 12:08:29 +02:00
holger krekel
abcadc4202 colors as used on the live web page 2014-06-29 09:47:50 +02:00
Christian Henz
b7f6a9f3fd Cleaner implementation of early handling of the '-c' command line switch.
--HG--
branch : explicit-ini-filename
2014-06-28 12:03:55 +02:00
christian@christian-linux.sarrazin.local
c8264385ea Implement the "-c" command line switch that allows to explicitly specifiy the config file to load.
This feature was requested in issue #174.

--HG--
branch : explicit-ini-filename
2014-06-27 17:42:37 +02:00
Floris Bruynooghe
ad8131be9e Re-add accidentally removed changelog items 2014-06-24 22:46:57 +01:00
holger krekel
54c88a6cf3 fix flakes issues 2014-06-16 11:27:32 +02:00
Floris Bruynooghe
115f15600f Add test for inter-dependent fixtures
Together with cc0a46a13ac4 this fixes issue 467.
2014-06-15 19:57:52 +01:00
Bruno Oliveira
65a145e2a7 Updated plugins index 2014-06-10 19:04:52 -03:00
holger krekel
5719a72eeb Merged in zyegfryed/pytest/zyegfryed/fixed-typo-noticed-by-dcramer-httpstwitt-1401780587159 (pull request #172)
Fixed typo noticed by @zeeg (https://twitter.com/zeeg/status/473676721128886272)
2014-06-03 09:49:02 +02:00
Sébastien Fievet
4bc4495115 Fixed typo noticed by @dcramer (https://twitter.com/zeeg/status/473676721128886272)
--HG--
branch : zyegfryed/fixed-typo-noticed-by-dcramer-httpstwitt-1401780587159
2014-06-03 07:30:14 +00:00
holger krekel
c66e9f8f0f fix typo, thanks @dcramer 2014-06-03 07:21:02 +02:00
holger krekel
52eafdc21e also add favicon 2014-06-01 12:36:31 +02:00
holger krekel
85c0d5481b incorporate the new pytest logo 2014-06-01 12:01:40 +02:00
Benjamin Peterson
fd9055fd11 fix test on Python 3.2 2014-05-31 14:51:05 -07:00
Benjamin Peterson
780bdda95a assert reinterpretation: try mangling attributes that look like private class vars (fixes #514) 2014-05-31 14:37:02 -07:00
Bruno Oliveira
fd4b461290 Updated plugins_index and updated python 3 to 3.4 2014-05-28 23:16:49 -03:00
holger krekel
040062e40c improve example for pytest integration with "python setup.py test"
which now has a generic "-a" or "--pytest-args" option where you
can pass additional options as a quoted string.  Thanks Trevor Bekolay.
2014-05-19 20:32:09 +02:00
holger krekel
d853e9167a Merged in tbekolay/pytest/tbekolay/better-setuptools-integration-in-goodpra-1400520902689 (pull request #171)
Better setuptools integration in goodpractices
2014-05-19 20:30:54 +02:00
Trevor Bekolay
d50ad270f0 Better setuptools integration in goodpractices
--HG--
branch : tbekolay/better-setuptools-integration-in-goodpra-1400520902689
2014-05-19 17:35:28 +00:00
holger krekel
30c93701a7 fix issue516: tell in getting-started about current dependencies.
cleanup setup.py a bit and specify supported versions. Thanks Jurko
Gospodnetic for the PR.
2014-05-14 09:58:34 +02:00
holger krekel
b507e1754c fix issue512 : document dependencies in getting-started doc. 2014-05-14 09:14:40 +02:00
holger krekel
748fce94fd Merged in jurko/pytest/setup cleanup (pull request #169)
setup.py cleanup/update (updated from pull request #167)
2014-05-14 09:10:13 +02:00
holger krekel
d6281b4206 - restore compatibility to old getvalueorskip behaviour
- introduce a better NOTSET representation to improve docs
2014-05-14 07:36:31 +02:00
holger krekel
b61ed2cf7e Merged in jurko/pytest/python 3.1 fix (pull request #168)
use py.builtin.callable instead of raw callable in _pytest/runner.py
2014-05-13 22:41:12 +02:00
Jurko Gospodnetić
9263f30c88 use py.builtin.callable instead of raw callable in _pytest/runner.py
This is consistent with how callable() is called from the rest of pytest code
(see _pytest/nose.py & _pytest/python.py) plus, as a nice side-effect, it
makes pytest work correctly on Python 3.1.

--HG--
branch : python 3.1 fix
2014-05-13 21:05:53 +02:00
Jurko Gospodnetić
8f9a88ef7a update the list of officially supported Python versions in setup.py
Removed Python 3.0 & 3.1 off the list and added Python 3.4.

--HG--
branch : setup cleanup
2014-05-13 19:03:17 +02:00
Jurko Gospodnetić
c64af0d9ce stylistic setup.py code cleanup
--HG--
branch : setup cleanup
2014-05-13 19:02:02 +02:00
holger krekel
9181df42da Merged in msabramo/pytest/require_argparse_for_py3_lt_32 (pull request #166)
setup.py: Require argparse for PY3 < 3.2
2014-05-11 19:30:11 +02:00
holger krekel
74e1a49dd7 remove the idea that nose support should be moved to a plugin. 2014-05-10 14:00:09 +02:00
holger krekel
468b1241a5 fix issue512: show "<notset>" for arguments which might not be set
in monkeypatch plugin.  Improves output in documentation.
2014-05-10 13:49:24 +02:00
Marc Abramowitz
24744cf5cf setup.py: Require argparse for PY3 < 3.2
E.g.: python3.1; noticed py31 failure while running tox for six

--HG--
branch : require_argparse_for_py3_lt_32
2014-05-09 23:40:06 -07:00
Floris Bruynooghe
ffc969b6c2 Do not list python 2.5 as supported in the docs 2014-05-01 22:25:03 +01:00
WooParadog
0567a8ee77 Add test for skipped case with utf-8 message 2014-04-24 10:45:39 +08:00
WooParadog
580c8525f0 Use processced skipreason for generating skip Junit node 2014-04-23 15:38:40 +08:00
WooParadog
d6010aa0c9 Also replace report.longrepr with bin_xml_escapeed skipreason 2014-04-23 14:50:21 +08:00
Floris Bruynooghe
c46e2cbbc7 Cache exception raised in fixtures according to their scope
Without this if a session scoped fixture fails it's setup it will
be re-tried each time it is requested.  Especially in case of
skip or failure exceptions this can be undesirable, but caching
makes sense for all exceptions.
2014-04-15 22:22:41 -04:00
Floris Bruynooghe
c47835f5ec Merge pull request #158, fixes issue 504 2014-04-15 11:43:38 -04:00
Floris Bruynooghe
412b56f7cf Changelog for issue 475 2014-04-14 18:12:29 -04:00
Floris Bruynooghe
faba432996 Improve error message if pytest.raises is used wrongly
If the type is not checked then an incomprehensible error will occur
later.  This enforces the type and raies the same exception/msg as
CPython does in that case.

Docstring unmodified, just re-justified for pep8 compat.
2014-04-14 18:09:10 -04:00
Andy Freeland
2ba23e8d08 issue504: verbose output displays node IDs for each test
Replace the verbose per-test reporting format of `file:line test_name RESULT`
with the node ID of the test, i.e. `file@line::class::method[param] RESULT`.

This patch does not update the examples in the docs; @hpk42 has a script
to regenerate those.

--HG--
branch : issue504
2014-04-14 17:42:02 -04:00
Floris Bruynooghe
d74f852fd6 Merged in rouge8/pytest/issue499 (pull request #157)
fix issue499: document selecting tests by node ID
2014-04-14 14:31:07 -04:00
Andy Freeland
1728798e81 Interal link to node ID explanation
--HG--
branch : issue499
2014-04-14 14:24:13 -04:00
Andy Freeland
53a8d20d88 fix issue499: document selecting tests by node ID
--HG--
branch : issue499
2014-04-14 12:27:55 -04:00
Floris Bruynooghe
61446faa17 Update changelog with last change 2014-04-12 17:01:05 -04:00
Floris Bruynooghe
9711e335d9 Change XPASS colour to be yellow rather then red
Unfortunately I'm not sure how to test this.
2014-04-12 10:27:12 -04:00
Anatoly Bubenkov
080a9d2f12 Merged in hpk42/pytest-hpk/nose_test_attr (pull request #154)
support nose-style __test__ attribute to disable collection of test modules/classes/functions
2014-04-10 22:38:53 +02:00
holger krekel
15af7e1662 fix tests to properly fail on failed collectiosn (which was hiding an error)
and also implement __test__=False for test functions properly.

--HG--
branch : nose_test_attr
2014-04-10 13:37:39 +02:00
holger krekel
e42cbc714f fix wrong merge
--HG--
branch : nose_test_attr
2014-04-10 12:58:10 +02:00
holger krekel
5e26e6e553 fix typo in changelog
--HG--
branch : nose_test_attr
2014-04-10 12:56:14 +02:00
holger krekel
d0a4d348fe merge default
--HG--
branch : nose_test_attr
2014-04-10 12:53:33 +02:00
holger krekel
494be731e3 support nose-style `__test__` attribute on modules, classes and
functions, including unittest-style Classes.  If set to True, the
test will not be collected.

--HG--
branch : nose_test_attr
2014-04-10 12:46:27 +02:00
Ronny Pfannschmidt
8ae244a06a Merged in hpk42/pytest-hpk/issue473 (pull request #152)
fix issue473: work around mock putting an unbound method into a class
2014-04-09 06:46:01 +02:00
holger krekel
f91049cec9 fix issue473: work around mock putting an unbound method into a class
dict when double-patching.

--HG--
branch : issue473
2014-04-08 12:50:13 +02:00
Ronny Pfannschmidt
270d0f89ba Merged in hpk42/pytest-hpk/issue498 (pull request #151)
fix issue498: if a fixture finalizer fails, make sure that the fixture
2014-04-07 13:51:03 +02:00
holger krekel
e382ed4245 fix issue439: clarify that capsys/capfd capture output during
test execution, not test setup.
2014-04-07 13:42:48 +02:00
holger krekel
ef7cb47b1e fix issue498: if a fixture finalizer fails, make sure that the fixture
is still invalidated.

--HG--
branch : issue498
2014-04-07 13:29:57 +02:00
holger krekel
6efde60b8b Merged in jurko/pytest/jurko/tox_usage (pull request #150)
runtox.py cleanup
2014-04-06 08:16:24 +02:00
Jurko Gospodnetić
fd059359cc make runtox.py not import external modules unless run as a script
Was not needed since the script actually does nothing unless run as a script.

--HG--
branch : jurko/tox_usage
2014-04-05 08:51:00 +02:00
Jurko Gospodnetić
c2c504797e stylistic runtox.py code cleanup
--HG--
branch : jurko/tox_usage
2014-04-05 08:49:30 +02:00
Jurko Gospodnetić
84f9f45f98 fix runtox.py failure when 'tox' is not available on the current system path
Now just assumes that the tox module is available in the executing Python
environment.

--HG--
branch : jurko/tox_usage
2014-04-05 08:47:04 +02:00
holger krekel
28aa4c891e bump version to 2.6.0.dev1 because i think we are going for a 2.6.0 release next
and not just a 2.5 maintenance one.
2014-04-03 22:27:04 +02:00
holger krekel
6ff0fdb977 fix issue443: fix skip examples to use proper comparison. Thanks Alex
Groenholm.
2014-04-03 22:26:10 +02:00
holger krekel
b0837693d0 add some changelog entries 2014-04-03 10:04:09 +02:00
holger krekel
52851e4388 Merged in jurko/pytest/fix_capfd_fixture_docstring (pull request #149)
correct a capfd fixture docstring typo
2014-04-03 10:02:00 +02:00
holger krekel
cbe31f3748 Merged in msabramo/pytest/makepyfile_utf8 (pull request #134)
Make makepyfile accept UTF-8 so a few cookie tests in test_assertrewrite.py
2014-04-03 10:00:24 +02:00
Jurko Gospodnetić
c9bbdf4f10 correct a capfd fixture docstring typo
--HG--
branch : fix_capfd_fixture_docstring
2014-04-03 09:59:04 +02:00
holger krekel
f984e94fca Merged in jurko/pytest/break_ExceptionInfo_reference_cycles (pull request #144)
break reference cycles caused by storing local reference to exception info
2014-04-03 09:47:41 +02:00
Anatoly Bubenkov
b4fe91943d Merged in hpk42/pytest-hpk/conftest-clean (pull request #148)
cleanup internal conftest handling and avoid the strange None entry in the conftest cache.
2014-04-03 09:38:47 +02:00
Anatoly Bubenkov
7d6317802e Merged in hpk42/pytest-hpk/issue486 (pull request #147)
fix issue486: better reporting and handling of early conftest loading failures
2014-04-03 00:19:05 +02:00
holger krekel
0365e5c3a0 cleanup internal conftest handling and avoid the strange None entry in the conftest cache.
(There is basically no reason to ask for conftestmodules without specifying a path.)

--HG--
branch : conftest-clean
2014-04-02 22:30:45 +02:00
holger krekel
e6859406f1 fix test on py33, thanks msabramo1 2014-04-02 20:49:57 +02:00
holger krekel
51cff6f106 fix issue486: better reporting and handling of early conftest loading failures
--HG--
branch : issue486
2014-04-02 20:42:41 +02:00
holger krekel
68e58e1493 add a test for robustness of capturing when a test closes FD1/2 2014-04-02 20:29:10 +02:00
holger krekel
9f7eac0ba1 Merged in msabramo/pytest/add_drone_io_to_README_rst (pull request #143)
README.rst: Add drone.io link
2014-04-02 19:13:26 +02:00
Floris Bruynooghe
b0e31dca86 Mention fix for issue 453 in changelog 2014-04-02 18:00:25 +01:00
holger krekel
7d10a57514 Merged in msabramo/pytest/remove_unused_import (pull request #146)
testing/test_capture.py: Remove unused stuff for PEP8 compliance
2014-04-02 18:56:46 +02:00
Marc Abramowitz
2c0f6207e9 test_capture.py: More PEP8. Remove unused cap in with.
--HG--
branch : remove_unused_import
2014-04-02 09:48:08 -07:00
Floris Bruynooghe
adb12d0d4f Escape newlines in result from assertrepr hook
The result from the pytest_assertrepr_compare hook should not include
any newlines since that will confuse the mini-formatting language used
by assertion.util.format_explanation.  So simply escape the included
newlines, this way hook writers do not have to worry about this at
all.

Fixes issue 453.
2014-04-02 17:35:22 +01:00
Floris Bruynooghe
844c141d10 Style fixes for pep8
Includes a quotation change for consistent style.
2014-04-02 17:16:37 +01:00
Marc Abramowitz
02d94e69f0 testing/test_capture.py: Remove unused import tempfile
--HG--
branch : remove_unused_import
2014-04-02 09:14:16 -07:00
Marc Abramowitz
1bc56f9838 README.rst: Remove drone.io build badge; keep link
hpk had concerns about the build badge confusing folks when shown on PyPI.

--HG--
branch : add_drone_io_to_README_rst
2014-04-02 06:41:33 -07:00
Jurko Gospodnetić
98ea8fae32 break reference cycles caused by storing local reference to exception info
Such reference cycles unnecessarily cause Python interpreter not to garbage
collect the objects referenced in those cycles as soon they could be collected,
and in turn cause the tests to use more memory than is strictly necessary.

--HG--
branch : break_ExceptionInfo_reference_cycles
2014-04-02 15:34:36 +02:00
holger krekel
36288c5134 fix issue493: don't run tests in doc directory with `python setup.py test`
(use tox -e doctesting for that)
2014-04-02 12:48:35 +02:00
holger krekel
83a3cc9c94 fix issue492: avoid leak in test_writeorg. Thanks Marc Abramowitz. 2014-04-02 12:32:30 +02:00
holger krekel
0c04b44919 fix issue492: avoid leak in test_writeorg 2014-04-02 12:32:21 +02:00
Marc Abramowitz
a5e8860feb README.rst: Add drone.io link and build badge image
--HG--
branch : add_drone_io_to_README_rst
2014-04-02 03:11:35 -07:00
holger krekel
8d95f89a6a fix issue496: add pytest-sugar github repo override and regen index pages, upload it. 2014-04-02 12:03:08 +02:00
holger krekel
3bca62e9e4 fix issue436: improved finding of initial conftest files from command
line arguments by using the result of parse_known_args rather than
the previous flaky heuristics.  Thanks Marc Abramowitz for tests
and initial fixing approaches in this area.
2014-04-02 11:29:23 +02:00
holger krekel
72b4534a0c add changelog entry for some PRs: improvements to pytest's own
test-suite leakage detection, courtesy of PRs from Marc Abramowitz
2014-04-02 09:51:24 +02:00
holger krekel
21b4280126 Merged in msabramo/pytest/test_writeorg_close_tempfile (pull request #136)
test_writeorg: Close a tempfile
2014-04-02 09:30:55 +02:00
holger krekel
30a9debaf1 Merged in msabramo/pytest/refactor_LsofFdLeakChecker (pull request #138)
testing/conftest.py: Refactor lsof fd leak checking
2014-04-02 09:24:16 +02:00
holger krekel
4c5718c78d Merged in msabramo/pytest/doc_plugins_pytest_sugar (pull request #141)
doc/en/plugins_index/index.txt: Update pytest-sugar
2014-04-02 09:20:42 +02:00
Marc Abramowitz
c93b949878 Update entry for pytest-sugar; GitHub icon instead of BitBucket, correct description
--HG--
branch : doc_plugins_pytest_sugar
2014-04-01 18:59:42 -07:00
Marc Abramowitz
cf34adb75f doc/en/plugins_index/index.txt: Update pytest-sugar
--HG--
branch : doc_plugins_pytest_sugar
2014-04-01 18:52:36 -07:00
Marc Abramowitz
f824a73143 Remove cast of fd to int and sorting
Casting of fd can break for non-numeric fd (e.g.: "rtd" on Linux) and isn't
necessary since we don't need to sort.

--HG--
branch : refactor_LsofFdLeakChecker
2014-04-01 15:36:54 -07:00
Marc Abramowitz
e45a33f029 testing/conftest.py: Reintialize config._openfiles for each test
And no longer need getopenfiles or config._numfiles

--HG--
branch : refactor_LsofFdLeakChecker
2014-04-01 14:13:11 -07:00
Marc Abramowitz
064e79761c Improve LsofFdLeakChecker; more reliable and useful leak checking
* Make it invoke lsof with options for machine-readable output
* Parse out file descriptor and filename from lsof output
* Draw attention to file descriptors now open that weren't open before

--HG--
branch : refactor_LsofFdLeakChecker
2014-04-01 13:41:35 -07:00
Marc Abramowitz
f7713c47e8 testing/conftest.py: Refactor lsof fd leak checking
Isolate the logic into one class to make easier to understand, more maintainable.
This may aid in later plugging in an alternative implementation, such as one
that uses psutil
(https://bitbucket.org/hpk42/pytest/pull-request/137/use-psutil-to-detect-open-files-in-tests/diff)

--HG--
branch : refactor_LsofFdLeakChecker
2014-04-01 10:15:27 -07:00
holger krekel
8e4e2ba244 merge main 2014-04-01 15:06:44 +02:00
holger krekel
3b8935c533 remove dupped_stdout logic and related changes, also simplify pytest_runtest_* calls to not use a contextlib with-decorator anymore. 2014-04-01 15:03:17 +02:00
holger krekel
ce8678e6d5 remove non-documented per-conftest capturing option and simplify/refactor all code accordingly. Also make capturing more robust against tests closing FD1/2 and against pdb.set_trace() calls. 2014-04-01 14:32:12 +02:00
holger krekel
2e1f6c85f6 introduce resume/suspend functionality for FDCapture and SysCapture,
fixing problems with early bailouts (from argparse's parse() function e.g.)
that wrote to stdout.
2014-04-01 14:19:58 +02:00
holger krekel
ca5e6830c6 avoid some redundancy by using SysCapture from FDCapture for manipulating sys.std{out,in,err} 2014-04-01 14:19:55 +02:00
holger krekel
69cbac8fb5 rename StdCaptureBase to MultiCapture 2014-04-01 14:19:52 +02:00
Marc Abramowitz
7301981f32 test_writeorg: Close a tempfile
--HG--
branch : test_writeorg_close_tempfile
2014-03-31 08:25:35 -07:00
Marc Abramowitz
555ba4159d Simplify tests; don't use u literal not supported in py32
--HG--
branch : makepyfile_utf8
2014-03-28 12:11:33 -07:00
Marc Abramowitz
f47ae74981 Make makepyfile accept UTF-8 so a few cookie tests in test_assertrewrite.py
don't need to be dedented.

--HG--
branch : makepyfile_utf8
2014-03-28 09:44:18 -07:00
holger krekel
e061ace099 fix toxenv spec for py33-pexpect, thanks Daniel Grana. 2014-03-28 14:51:00 +01:00
holger krekel
85d52481b1 fix issue483: trial/py33 works now properly. Thanks Daniel Grana for PR. 2014-03-28 14:47:34 +01:00
holger krekel
47379d4a79 Merged in dangra/pytest (pull request #132)
no need for im_func and it does not exists in python3
2014-03-28 14:46:34 +01:00
Daniel Grana
0cb9d26d83 add py33-trial tox environment 2014-03-28 10:44:51 -03:00
holger krekel
95cc114b34 add changelog entry:
fix issue412: messing with stdout/stderr FD-level streams is now
captured without crashes.
2014-03-28 11:29:29 +01:00
holger krekel
9d716a39d6 fix issue412 and other encoding issues. Streamline dupfile() into
a new more thoughtful safe_text_dupfile helper.
2014-03-28 11:27:02 +01:00
holger krekel
923dcfd620 cleanup and refine issue412 test (still failing on py33) 2014-03-28 09:46:38 +01:00
holger krekel
b5467645d3 merge 2014-03-28 09:27:44 +01:00
holger krekel
a65380941d Merged in msabramo/pytest/sys_meta_path_remove_hook_only_if_present (pull request #133)
Only try to remove hook from sys.meta_path if it's present
2014-03-28 09:10:58 +01:00
Marc Abramowitz
17d7c60735 test_sys_meta_path_munged: Simplify with makepyfile
--HG--
branch : sys_meta_path_remove_hook_only_if_present
2014-03-28 01:03:52 -07:00
Marc Abramowitz
81f822d528 Only try to remove hook from sys.meta_path if it's present
Prevent error on exit if some code messes with sys.meta_path and removes the
assertionrewrite hook (CaptureMock seems to do this):

      File "/Users/marca/dev/hg-repos/pytest/_pytest/assertion/__init__.py", line 64, in pytest_unconfigure
        sys.meta_path.remove(hook)
    ValueError: list.remove(x): x not in list

--HG--
branch : sys_meta_path_remove_hook_only_if_present
2014-03-28 00:33:12 -07:00
holger krekel
0b340aa1f6 simplify some capturing tests 2014-03-28 07:55:07 +01:00
holger krekel
859915dc5e simplify capturing funcarg handling 2014-03-28 07:13:08 +01:00
holger krekel
a8f4f49a82 simplify reset/stop_capturing and fix capturing wrt to capturing simple os.write() calls 2014-03-28 07:11:25 +01:00
holger krekel
e18c3ed494 unify and normalize Sys/FD Capturing classes
* * *
more unification
2014-03-28 07:03:37 +01:00
holger krekel
2263fcf6b7 remove unused "suspend/resume" on capturing, some formatting cleanup 2014-03-28 07:03:34 +01:00
Daniel Grana
b96d552dbd no need for im_func and it does not exists in python3 2014-03-27 23:57:18 -03:00
Ronny Pfannschmidt
2b2c1e5b7b condition for python3 of the xfailing test for 412 2014-03-27 14:01:38 +01:00
holger krekel
7b63fa5966 merge in current default 2014-03-27 13:57:54 +01:00
Ronny Pfannschmidt
b18040337a xfailing test for issue 412 2014-03-27 13:53:59 +01:00
holger krekel
42e0d7970c Merged in nloadholtes/pytest/nloadholtes/slight-change-to-the-wording-for-readabi-1395890493571 (pull request #131)
Slight change to the wording for readability
2014-03-27 06:40:35 +01:00
Nick Loadholtes
ed0a4fe23b Slight change to the wording for readability
--HG--
branch : nloadholtes/slight-change-to-the-wording-for-readabi-1395890493571
2014-03-27 03:21:58 +00:00
holger krekel
bb0632c7ad extend test 2014-03-26 19:37:49 +01:00
holger krekel
84ab194516 add changelog: merge PR123: improved integration with mock.patch decorator on tests. 2014-03-26 19:06:56 +01:00
holger krekel
530cae9204 Merged in cgilling/pytest (pull request #123)
Fix to work properly when @patch is used with new not equal to DEFAULT
2014-03-26 19:05:46 +01:00
holger krekel
9dc43e84dc Merged in msabramo/pytest/help_show_args_with_equals_instead_of_space (pull request #130)
_pytest/config.py: In --help, show args with `=` instead of space.
2014-03-26 19:04:35 +01:00
Marc Abramowitz
8af265da04 _pytest/config.py: In --help, show args with = instead of space.
The `=` is better because it encourages folks to use the form that doesn't
suffer from issue #436 (https://bitbucket.org/hpk42/pytest/issue/436), which
can cause the arg to be treated as an "anchor" and used as the (unexpected)
path for searching for conftest.py files.

--HG--
branch : help_show_args_with_equals_instead_of_space
2014-03-26 10:47:30 -07:00
Chris Gilling
e3b9382122 use sys.modules.get correctly and reference DEFAULT with respect to it 2014-03-26 09:36:02 -07:00
Chris Gilling
c3f4eb6d57 change try/except to sys.module.get and a conditional 2014-03-26 09:27:33 -07:00
holger krekel
892aa457be fix issue472: clarify that `pytest.config.getvalue()` cannot work
if it's triggered ahead of command line parsing.
2014-03-26 07:15:54 +01:00
holger krekel
8f7b53e55b fix issue490: include pytest_load_initial_conftests in documentation
and improve docstring.
2014-03-25 14:43:58 +01:00
holger krekel
d27c377817 tentatively fix py33 and py25 compat 2014-03-14 15:58:16 +01:00
holger krekel
50abe43216 fix issue #479: properly handle nose/unittest(2) SkipTest exceptions
during collection/loading of test modules.  Thanks to Marc Schlaich
for the complete PR.
2014-03-14 15:44:39 +01:00
holger krekel
ddc67ca13a Merged in schlamar/pytest (pull request #129)
Fixed race condition with SkipTest when module not in sys.modules on collection.
2014-03-14 15:39:01 +01:00
holger krekel
a1d3da4027 Merged in nicoddemus/pytest/integrate-plugin-index-docs (pull request #120)
Integrating plugin_index docs and misc improvements
2014-03-14 15:34:03 +01:00
schlamar
85e7b11ef5 Removed unnecessary iteration in nose.pytest_runtest_makereport. 2014-03-14 15:29:42 +01:00
schlamar
77e1f93ca1 Fixed pyflakes errors. 2014-03-14 14:25:36 +01:00
schlamar
94b1ce65c6 Fixed race condition with SkipTest when module not in sys.modules on collection. 2014-03-14 14:04:54 +01:00
holger krekel
f5b992f68a Merged in jurko/pytest/doc_typo_correction (pull request #122)
fix documentation typo
2014-03-14 13:10:33 +01:00
holger krekel
24a458b4c8 Merged in graingert/pytest/graingert/pep8-good-practices-code-1394196858258 (pull request #125)
pep8 good practices code
2014-03-14 13:06:53 +01:00
holger krekel
ac1d277225 simplify pdb disabling of capturing, also accomodate the new semantics
that capturing is always on during a test session.
2014-03-14 12:49:37 +01:00
holger krekel
9777703e03 - turn on capturing before early conftest loading and make terminal writer
use the original stream.

- avoid resetting capture FDs/sys.stdout for each test by keeping capturing
  always turned on and looking at snapshotted capturing data during runtest
  and collection phases.
2014-03-14 12:49:36 +01:00
holger krekel
f43cda9681 implement a new hook type: hook wrappers using a "yield" to distinguish
between working at the front and at the end of a hook call chain.
The idea is to make it easier for a plugin to "wrap" a certain hook
call and use context managers, in particular allow a major cleanup of
capturing.
2014-03-14 12:49:35 +01:00
holger krekel
b47fdbe0a7 remove externally setting and dealing with "item.outerr" from capturing in favor of a direct interface for adding reporting sections to items.
* * *
refactor makereport implementation to avoid recursion with __multicall__
2014-03-14 12:49:34 +01:00
holger krekel
cde970be69 remove unneccessary indirections and options 2014-03-14 12:49:34 +01:00
holger krekel
cfd43a9b02 add changelog for warning system, bump internal version 2014-03-14 08:15:38 +01:00
holger krekel
ebd10aa6b4 shrink and merge the somewhat obscure and undocumented internal hinting
system with the new warnings one
2014-03-11 22:10:51 +01:00
holger krekel
24db492f53 warn if instances are callable and have a test name 2014-03-11 22:10:18 +01:00
holger krekel
1b387bea62 introduce warning system with this API:
- node.warn() for a node-specific warning
- config.warn() for a global non-node specific warning

Each warning is accompanied by a "warning number" so that we can later
introduce mechanisms for surpressing them.

Each warning will trigger a call to pytest_report_warn(number, node, message)
which is by default implemented by the TerminalReporter which introduces
a new option "-rw" to show details about warnings.
2014-03-11 22:10:17 +01:00
Thomas Grainger
9528b64f7f pep8 good practices code
--HG--
branch : graingert/pep8-good-practices-code-1394196858258
2014-03-07 12:51:51 +00:00
holger krekel
b96559149c Merged in jurko/pytest/pdb_doc_update (pull request #118)
update PDB related pytest docs
2014-03-06 08:36:42 +01:00
Chris Gilling
3388d82c1c Fix to work properly when @patch is used with new not equal to DEFAULT
also updated test_mock to include this situation
2014-03-03 10:36:59 -08:00
Jurko Gospodnetić
9985a7cdca fix documentation typo
--HG--
branch : doc_typo_correction
2014-03-02 22:52:38 +01:00
Bruno Oliveira
1d00c5e109 Using github and bitbucket icons on plugins_index page
--HG--
branch : integrate-plugin-index-docs
2014-02-18 22:40:36 -03:00
Bruno Oliveira
0559f11aa5 Improved text on plugins_index
- Removed "beta" status from it;
- Added links to pytest-plugs app;

--HG--
branch : integrate-plugin-index-docs
2014-02-18 21:33:13 -03:00
Bruno Oliveira
2893cddb68 plugins_index no longer has the package names hard-coded
small number of changes:
- removed hard-coded links to package release versions, using
  a placeholder "latest" instead which is understood by pytest-plugs
- testing against pytest-2.5.2

This changes were implemented so this page only needs
to be updated after pytest releases, not after each package version changes;.
2014-02-11 23:38:30 -02:00
Jurko Gospodnetić
6910641266 reword PDB usage documentation
Documented that since pytest 2.4.0 you can use the raw pdb.set_trace() call
directly without the pytest.set_trace() wrapper or explicitly disabling pytest's
output capture using 'py.test -s'.

Clearly stated how pytest (since version 2.0.0.) automatically disables its
output capture when entering an interactive PDB debugger. This avoids confusing
new users because their tests display different output when running with or
without entering an interactive debugger (even if user does nothing in that
interactive debugger session other than exit it and continue with the regular
test execution).

--HG--
branch : pdb_doc_update
2014-02-01 10:19:09 +01:00
Jurko Gospodnetić
4b81a07303 make all 'PDB' doc references be recognized as links
--HG--
branch : pdb_doc_update
2014-02-01 10:11:42 +01:00
Jurko Gospodnetić
7eb765578a correct inconsistent comment wording
Once the 'the' article was used before 'first' and once it was not, all within
the same code example.

--HG--
branch : pdb_doc_update
2014-02-01 10:07:54 +01:00
holger krekel
e2cf3e0932 Added tag 2.5.2 for changeset 421d3b4d150d 2014-01-29 14:09:33 +01:00
holger krekel
1830de2c13 make it clear that this xfail is an unimplemented feature, nothing more. 2014-01-29 13:56:24 +01:00
holger krekel
25ab906b8b add release announcement, bump version to 2.5.2,
add links to plugins index, regenerate doc examples.
2014-01-29 13:47:11 +01:00
holger krekel
8a3b4b9c37 require py>=1.2.20 2014-01-29 13:11:40 +01:00
holger krekel
2b8a54d5d9 refine skipif to use direct booleans, to help with flakes 2014-01-29 11:46:36 +01:00
holger krekel
4eabfed651 refactor lsof checking and fix an lsof leak in pypy 2014-01-29 11:18:15 +01:00
holger krekel
505a34bb85 fix flakes failures 2014-01-29 10:20:13 +01:00
holger krekel
2dade6ed00 add changelog entry about issue429, adapt README 2014-01-29 09:00:14 +01:00
Floris Bruynooghe
825ea9bfa1 Fix assertrepr for mojibake
If the compared text was in bytes and not actually valid text
(i.e. could not be encoded to text/unicode using the default encoding)
then the assertrepr would fail with an EncodingError.  This ensures
that the internal string is always valid unicode, converting any bytes
safely to valid unicode.  This is done using repr() which then needs
post-processing to fix the encompassing quotes and un-escape newlines.

This fixes issue 429.
2014-01-29 00:42:58 +00:00
Floris Bruynooghe
cc1186242c Avoid wasted string concatenation and improve english 2014-01-29 00:39:04 +00:00
holger krekel
86284689a3 simplify loop which turns direct funcarg parametrization to indirect 2014-01-27 12:53:44 +01:00
holger krekel
c70d020bf3 allow positional args to tox invocation 2014-01-27 12:42:06 +01:00
holger krekel
4622c28ffd setupstate.addfinalizer(): fix docstring and remove related unit test not covering functional reality 2014-01-26 12:44:21 +01:00
holger krekel
899998cf9c Merged in hpk42/pytest-capsimple/capsimple1 (pull request #115)
some simplifications in capturing code
2014-01-26 12:07:45 +01:00
holger krekel
6f385fb4ea remove "mixed" capturing mode which is not used by pytest
--HG--
branch : capsimple1
2014-01-25 19:56:27 +01:00
holger krekel
18e12cbd67 remove "StdCapture*.call" classmethod because pytest does not use it.
--HG--
branch : capsimple1
2014-01-25 19:43:57 +01:00
holger krekel
3cf4e133cc remove now parameter because pytest only used now==False everywhere
--HG--
branch : capsimple1
2014-01-25 19:42:45 +01:00
holger krekel
d53bfe0aa7 Merged in RonnyPfannschmidt/pytest/multi-usageerror (pull request #113)
Make one usage error for every argument that fails instead of bailing at the first only
2014-01-25 11:04:53 +01:00
Ronny Pfannschmidt
97da43d909 merge from default
--HG--
branch : multi-usageerror
2014-01-25 10:42:21 +01:00
holger krekel
ee080ce8a5 Merged in jurko/pytest/remove_github_references (pull request #112)
remove references to the no longer used github mirror
2014-01-25 10:30:31 +01:00
Jurko Gospodnetić
741a3e8602 remove references to the no longer used github mirror
--HG--
branch : remove_github_references
2014-01-25 09:11:55 +01:00
Ronny Pfannschmidt
177637bfb9 Redo the Capture integration propperly 2014-01-24 21:22:19 +01:00
Piotr Banaszkiewicz
ae64221c34 Contribution guide: added pull request button image 2014-01-24 20:01:04 +01:00
Piotr Banaszkiewicz
22017f11d0 Contribution guide: removed confusion regarding git 2014-01-24 19:37:44 +01:00
Piotr Banaszkiewicz
c1eaad7d57 Contribution guide: added "what is pull request" section 2014-01-24 19:21:21 +01:00
holger krekel
8e6d538a57 address issue416: clarify docs as to conftest.py loading semantics 2014-01-23 15:25:01 +01:00
holger krekel
0836d74ae7 add Jurko to authors/contributors file 2014-01-23 15:08:24 +01:00
holger krekel
a9e5bd52d3 remove github links 2014-01-23 14:50:58 +01:00
Anatoly Bubenkov
b4b5e358c3 merge with mainline 2014-01-23 13:21:00 +01:00
Anatoly Bubenkov
4190809d1a remove the github contribution section 2014-01-23 13:19:49 +01:00
holger krekel
4e2a820c6a add Daniel Greensfeld 3-part blog series about pytest 2014-01-23 13:07:28 +01:00
holger krekel
14a43fffee have travis use the devpi index to get the pylib dependency 2014-01-23 12:18:20 +01:00
holger krekel
245d39f52d Merged in jurko/pytest/document_ExceptionInfo_ref_cycle (pull request #109)
document explicitly clearing local references to pytest.raises() results (redo of pull request #98)
2014-01-23 11:42:51 +01:00
holger krekel
ac0b862f8f speak about "pytest" rather than "py.test". Thanks Jurko. 2014-01-23 11:42:20 +01:00
holger krekel
c41db8ebbb refine contributing text in several places 2014-01-23 11:38:05 +01:00
Jurko Gospodnetić
75c124ea17 reword note on explicitly clearing local references to pytest.raises() results
Made it clearer that clearing such references is not mandatory and is only an
optional step which may help the Python interpreter speed up its garbage
collection.

--HG--
branch : document_ExceptionInfo_ref_cycle
2014-01-23 11:36:04 +01:00
Anatoly Bubenkov
ab13c3f362 add explicit branch creation note 2014-01-23 10:51:45 +01:00
holger krekel
c9af19dae1 rename, refine and link to new contributing doc from several places. 2014-01-23 10:21:06 +01:00
Jurko Gospodnetić
ffffac27f9 document explicitly clearing local references to pytest.raises() results
pytest.raises() returns an ExceptionInfo object which, if a local reference is
made to it, forms a reference cycle:
  ExceptionInfo
  --> exception
  --> stack frame raising the exception
  --> current stack frame
  --> current local variables
  --> Exception Info

Such a reference cycle would then prevent any local variables in the current
stack frame, or any of its child stack frames involved in the same reference
cycle, from being garbage collected until the next reference cycle garbage
collection phase. This unnecessarily increases the program's memory footprint
and potentially slows it down.

This situation is based on a similar one described in the official 'try'
statement Python documentation for locally stored exception references.

--HG--
branch : document_ExceptionInfo_ref_cycle
2014-01-23 09:46:36 +01:00
Anatoly Bubenkov
618bd56acf add Piotr Banaszkiewicz 2014-01-23 00:54:25 +01:00
Anatoly Bubenkov
402232e60f merge pbanaszkiewicz/contributiondocs 2014-01-23 00:52:49 +01:00
holger krekel
400b51caf6 mark encoding test as xfail also on py2 2014-01-22 22:18:33 +01:00
holger krekel
9aaf0fd340 backing out Ronny's PR because it was merged too early (still has failing tests) 2014-01-22 22:15:40 +01:00
Ronny Pfannschmidt
8976b3ee0e stop exposing capsys/capfd.capture 2014-01-22 21:52:32 +01:00
Ronny Pfannschmidt
ac2f2b1deb add notes on the copied pylib version 2014-01-22 21:50:07 +01:00
Ronny Pfannschmidt
0be961a0f3 capture tests: move imports and declarations to the top 2014-01-22 21:46:35 +01:00
Ronny Pfannschmidt
b4a397d153 kill ancient capture devnullpath, os.devnull exists since py 2.4 2014-01-22 21:37:59 +01:00
Ronny Pfannschmidt
d1a9ab3df0 small cleanp 2014-01-22 21:04:00 +01:00
Ronny Pfannschmidt
0ede968ec0 kill the str magic of Encodedfile 2014-01-22 21:03:49 +01:00
Ronny Pfannschmidt
5f21abc3a3 move imports and declarations to the top 2014-01-22 20:48:17 +01:00
Ronny Pfannschmidt
e2bb81124c simplify StdCaptureFD snapshot reading 2014-01-22 19:48:10 +01:00
Ronny Pfannschmidt
ea18e9656b rewrite all _pytest.capture uses of py.io to _pytest.capture 2014-01-22 19:44:20 +01:00
Ronny Pfannschmidt
3cc58c2f78 rewrite all testing uses of py.io to _pytest.capture 2014-01-22 19:32:23 +01:00
Ronny Pfannschmidt
0ac94134f5 initial code import for capture transfer 2014-01-22 19:04:38 +01:00
Ronny Pfannschmidt
c142f2551d xfailing test for captire encoding issues with binary stdio 2014-01-22 18:07:54 +01:00
holger krekel
cccfaa81fb fix issue413: exceptions with unicode attributes are now printed
correctly also on python2 and with pytest-xdist runs. (the fix
requires py-1.4.20)
2014-01-22 17:48:56 +01:00
Piotr Banaszkiewicz
d960fb78fc Contribution guide: moved tox inst. instructions up
--HG--
branch : contributiondocs
2014-01-22 17:05:11 +01:00
holger krekel
d02d0bb7b7 Merged in pelme/pytest/py2_pkg_skip (pull request #107)
fixed issue428: Skip test for packages without __init__.py on Python 2
2014-01-22 14:46:22 +01:00
Andreas Pelme
fe4cdd8a90 fixed issue428: Skip test for packages without __init__.py on Python 2
--HG--
branch : py2_pkg_skip
2014-01-22 14:32:22 +01:00
Jurko Gospodnetić
54a143e6a8 add test: '--markers' listing info from plugins in current folder
When pytest is called with the '--markers' option, it should collect marker
information from the current folder, and they should get loaded and used
correctly before the '--markers' output is constructed.
2014-01-22 14:16:39 +01:00
holger krekel
3a4f69734a remove superflous line 2014-01-22 13:54:25 +01:00
Piotr Banaszkiewicz
fbdc6e8cc0 Addressed contribution guide issues: virtualenv, links, Github mirror, RST rendering
--HG--
branch : contributiondocs
2014-01-22 12:19:33 +01:00
Piotr Banaszkiewicz
c2c44f0ffc Moved contribution guide to the rootdir/CONTRIBUTING.txt
--HG--
branch : contributiondocs
2014-01-22 11:37:02 +01:00
Floris Bruynooghe
e12fe64b54 Include py version in the terminal output
This can help to reproduce bugs when looking at the output pasted into
bug reports.
2014-01-22 11:27:15 +01:00
Piotr Banaszkiewicz
5240252164 New enthusiastic contribution guide based on Audreyr's cookiecutter-pypackage
Audrey's code is BSD, so there should be no problem with licensing.

I've covered:
* contribution types (with hints)
* steps to start with pytest development
* testing pytest
* basics of hg

--HG--
branch : contributiondocs
2014-01-22 11:24:58 +01:00
holger krekel
1ffc006363 fixed circular imports by reverting a few py.test -> pytest substitions. 2014-01-22 11:17:25 +01:00
holger krekel
836232e544 fix issue425: mention at end of "py.test -h" that --markers
and --fixtures work according to specified test path (or current dir)
2014-01-22 10:24:22 +01:00
holger krekel
2539e5a352 Merged in derdon/pytest/no-p-option (pull request #102)
added docs about the `no:` syntax for the -p option
2014-01-20 13:22:31 +01:00
Jurko Gospodnetić
8e457338ee fix handling MarkDecorators called with a single positional plus keyword args
When a MarkDecorator instance is called it does the following:
  1. If called with a single class as its only positional argument and no
     additional keyword arguments, it attaches itself to the class so it gets
     applied automatically to all test cases found in that class.
  2. If called with a single function as its only positional argument and no
     additional keyword arguments, it attaches a MarkInfo object to the
     function, containing all the arguments already stored internally in the
     MarkDecorator.
  3. When called in any other case, it performs a 'fake construction' call, i.e.
     it returns a new MarkDecorator instance with the original MarkDecorator's
     content updated with the arguments passed to this call.

When Python applies a function decorator it always passes the target class/
function to the decorator as its positional argument with no additional
positional or keyword arguments. However, when MarkDecorator was deciding
whether it was being called to decorate a target function/class (cases 1. & 2.
as documented above) or to return an updated MarkDecorator (case 3. as
documented above), it only checked that it received a single callable positional
argument and did not take into consideration whether additional keyword
arguments were being passed in as well.

With this change, it is now possible to create a pytest mark storing a function/
class parameter passed as its only positional argument and accompanied by one or
more additional keyword arguments. Before, it was only possible to do so if the
function/class parameter argument was accompanied by at least one other
positional argument.

Added a related unit test.

Updated MarkDecorator doc-string.
2014-01-20 01:27:33 +01:00
Simon Liedtke
d92ee8c3c3 added docs about the no: syntax for the -p option
--HG--
branch : no-p-option
2014-01-19 22:05:14 +01:00
Jurko Gospodnetić
492c60c202 fix doc typo 2014-01-19 10:26:55 +01:00
holger krekel
86ef81454f fix name 2014-01-19 09:13:06 +01:00
holger krekel
675669c52e added changelog: fixed docs and code to use "pytest" instead of "py.test"
everywhere.  Thanks Jurko Gspodnetic for the complete PR.
2014-01-18 14:53:04 +01:00
holger krekel
92c5d395a2 Merged in jurko/pytest (pull request #100)
update README.rst docs - pytest is compatible with Python 2.5 instead of 2.4
2014-01-18 14:51:53 +01:00
Jurko Gospodnetić
fa4ea1d9e8 update README.rst docs - pytest is compatible with Python 2.5 instead of 2.4 2014-01-18 13:11:17 +01:00
Jurko Gospodnetić
657a395839 fix comment typos 2014-01-18 12:39:16 +01:00
Jurko Gospodnetić
9fb2079458 replace py.test module references with pytest
The only remaining 'py.test' references are:
 * those referring to the 'py.test' executable
 * those in code explicitly testing py.test/pytest module compatibility
 * those in old CHANGES documentation
 * those in documentation generated based on external data
 * those in seemingly unfinished & unmaintained Japanese documentation

Minor stylistic changes and typo corrections made to documentation next to
several applied py.test --> pytest content changes.
2014-01-18 12:31:33 +01:00
Jurko Gospodnetić
83620ced2e trim trailing spaces 2014-01-18 10:40:20 +01:00
Bruno Oliveira
1fb824cd28 plugins_index: status images now link to actual tox output 2014-01-15 20:48:11 -02:00
Bruno Oliveira
0d35994fb8 Updated plugins_index.txt after changes in plugin_index.py 2014-01-15 20:32:11 -02:00
Bruno Oliveira
3a37f33d99 Improvements in plugins_index.txt
- Removed author and email in favor of repository link.
  Repository link is obtained from the 'home_page' field
  obtained from pypi. For plugins that don't have
  that field set, function obtain_override_repositories
  is used to override it in favor of known repositories url.

- Shortened "Python 2.7" in favor of "py27" to save space;
  Same for "Python 3.3".
2014-01-15 20:26:05 -02:00
Bruno Oliveira
ddfb2d5f3a Removing test_plugins_index
This test seems unnecessary now, since after every change we have
to generate plugins_index.txt and manually check to ensure it is
correct.
2014-01-15 19:20:53 -02:00
holger krekel
d81c0e9a92 remove build status that shows on pypi -- doesn't make sense because it shows the current trunk, not the released version. And start a new doc/en/status.txt 2014-01-11 10:46:07 +01:00
holger krekel
048cb71bf6 Merged in lakka/pytest//minor-doc-fix-in-skippingtxt-also-submi-1387492852421 (pull request #94)
Minor doc fix in skipping.txt.  Also submitted at Github before I realised that this was the master repo.  Will close over there.
2014-01-10 10:44:12 +01:00
Daniel Hahler
903fd144ff doc: fix desc for parametrize
- the parameter is called `expected`, not `output`
 - s/that that/that/
2014-01-09 22:27:23 +01:00
Jurko Gospodnetić
d51e27a5cb correct documentation typo 2013-12-28 17:05:17 +01:00
holger krekel
064290a606 Merge pull request #11 from pmuller/patch-1
Fix minor typo in special.txt
2013-12-20 11:37:39 -08:00
Philippe Muller
e6ae68c0cc Fix minor typo in special.txt 2013-12-20 14:01:17 +01:00
lakka
43f970ab6b Minor doc fix in skipping.txt. Also submitted at Github before I realised that this was the master repo. Will close over there.
--HG--
branch : /minor-doc-fix-in-skippingtxt-also-submi-1387492852421
2013-12-19 22:41:07 +00:00
holger krekel
49b9f9091a Merge pull request #9 from lukaszb/mark-error-message
Updated error message to be more helpful.
2013-12-19 07:13:13 -08:00
Lukasz Balcerzak
99277be25f Updated error message to be more helpful
Also, added misssing test
2013-12-19 14:29:57 +01:00
holger krekel
699892bd03 fix issue409 -- better interoperate with cx_freeze by not
trying to import from collections.abc which causes problems for py27/cx_freeze.
2013-12-18 14:56:45 +01:00
Bruno Oliveira
70c1503afc updated plugins_index for pytest 2.5.1 release 2013-12-17 21:52:26 -02:00
Bruno Oliveira
ee5d2eb696 plugins_index.py and test run under py33
changed a message a bit since issue405 has actually been resolved
2013-12-17 21:42:51 -02:00
Bruno Oliveira
2058f11931 Formatted plugins_index files to use a 80 char width
- Formatted code to follow pep-8 more closely;
- Got rid of header comments to better follow py.test coding style;
2013-12-17 19:34:07 -02:00
Bruno Oliveira
53a9ee21d4 Fixed test_plugins_index to work on python 2.6
- Expected and obtained modules now use .rst to avoid being picked as doctests
- Fixed test_plugins_index.expected to use the real py.test version
2013-12-17 19:14:57 -02:00
holger krekel
04118a5761 just use "sans-serif" as the default font, thankfully recommended by hynek. 2013-12-17 14:59:29 +01:00
holger krekel
c101c30690 change to the non-serif version of "Deja Vu" 2013-12-17 13:48:59 +01:00
holger krekel
0e664d3471 don't use guidea as font as it appears to give troubles to windows/chrome
users, see also here: http://stackoverflow.com/questions/11487427/is-there-any-font-smoothing-in-google-chrome
2013-12-17 13:21:39 +01:00
holger krekel
fcb1749f10 a few minor fixes and removing google+ stuff. 2013-12-17 11:24:58 +01:00
holger krekel
180eb098f1 Added tag 2.5.1 for changeset 039d543d1ca0 2013-12-17 10:52:03 +01:00
Ronny Pfannschmidt
cf37c477bb output errors for all failures of specific collection
when issueing a command with many specific items to collect,
print all collect failures instead of just the first one

--HG--
branch : multi-usageerror
2013-09-08 22:26:51 +02:00
147 changed files with 4914 additions and 2308 deletions

View File

@@ -9,6 +9,7 @@ lib/
bin/
include/
.Python/
.env/
# These lines are suggested according to the svn:ignore property
# Feel free to enable them by uncommenting them
@@ -27,6 +28,7 @@ dist/
*.egg-info
issue/
env/
env3/
3rdparty/
.tox
.cache

View File

@@ -64,3 +64,9 @@ af860de70cc3f157ac34ca1d4bf557a057bff775 2.4.0
8828c924acae0b4cad2e2cb92943d51da7cb744a 2.4.1
8d051f89184bfa3033f5e59819dff9f32a612941 2.4.2
a064ad64d167508a8e9e73766b1a4e6bd10c85db 2.5.0
039d543d1ca02a716c0b0de9a7131beb8021e8a2 2.5.1
421d3b4d150d901de24b1cbeb8955547b1420483 2.5.2
60725b17a9d1af4100abb8be3f9f4ddf6262bf34 2.6.0
60725b17a9d1af4100abb8be3f9f4ddf6262bf34 2.6.0
88af949b9611494e2c65d528f9e565b00fb7e8ca 2.6.0
a4f9639702baa3eb4f3b16e162f74f7b69f3f9e1 2.6.1

View File

@@ -2,7 +2,8 @@ language: python
# command to install dependencies
install: "pip install -U detox"
# # command to run tests
script: detox --recreate
script: detox --recreate -i ALL=https://devpi.net/hpk/dev/
notifications:
irc:
- "chat.freenode.net#pytest-dev"

19
AUTHORS
View File

@@ -1,7 +1,7 @@
Holger Krekel, holger at merlinux eu
merlinux GmbH, Germany, office at merlinux eu
Contributors include::
Contributors include::
Ronny Pfannschmidt
Benjamin Peterson
@@ -9,21 +9,21 @@ Floris Bruynooghe
Jason R. Coombs
Wouter van Ackooy
Samuele Pedroni
Anatoly Bubenkoff
Anatoly Bubenkoff
Brianna Laugher
Carl Friedrich Bolz
Armin Rigo
Maho
Jaap Broekhuizen
Jaap Broekhuizen
Maciek Fijalkowski
Guido Wesdorp
Brian Dorsey
Ross Lawley
Ralf Schmitt
Chris Lamb
Chris Lamb
Harald Armin Massa
Martijn Faassen
Ian Bicking
Ian Bicking
Jan Balster
Grig Gheorghiu
Bob Ippolito
@@ -36,3 +36,12 @@ Katarzyna Jachim
Christian Theunert
Anthon van der Neut
Mark Abramowitz
Piotr Banaszkiewicz
Jurko Gospodnetić
Marc Schlaich
Christopher Gilling
Daniel Grana
Andy Freeland
Trevor Bekolay
David Mohr
Nicolas Delaby

190
CHANGELOG
View File

@@ -1,3 +1,193 @@
2.6.2
-----------
- Added function pytest.freeze_includes(), which makes it easy to embed
pytest into executables using tools like cx_freeze.
See docs for examples and rationale. Thanks Bruno Oliveira.
- Improve assertion rewriting cache invalidation precision.
- fixed issue561: adapt autouse fixture example for python3.
- fixed issue453: assertion rewriting issue with __repr__ containing
"\n{", "\n}" and "\n~".
- fix issue560: correctly display code if an "else:" or "finally:" is
followed by statements on the same line.
- Fix example in monkeypatch documentation, thanks t-8ch.
- fix issue572: correct tmpdir doc example for python3.
- Do not mark as universal wheel because Python 2.6 is different from
other builds due to the extra argparse dependency. Fixes issue566.
Thanks sontek.
2.6.1
-----------------------------------
- No longer show line numbers in the --verbose output, the output is now
purely the nodeid. The line number is still shown in failure reports.
Thanks Floris Bruynooghe.
- fix issue437 where assertion rewriting could cause pytest-xdist slaves
to collect different tests. Thanks Bruno Oliveira.
- fix issue555: add "errors" attribute to capture-streams to satisfy
some distutils and possibly other code accessing sys.stdout.errors.
- fix issue547 capsys/capfd also work when output capturing ("-s") is disabled.
- address issue170: allow pytest.mark.xfail(...) to specify expected exceptions via
an optional "raises=EXC" argument where EXC can be a single exception
or a tuple of exception classes. Thanks David Mohr for the complete
PR.
- fix integration of pytest with unittest.mock.patch decorator when
it uses the "new" argument. Thanks Nicolas Delaby for test and PR.
- fix issue with detecting conftest files if the arguments contain
"::" node id specifications (copy pasted from "-v" output)
- fix issue544 by only removing "@NUM" at the end of "::" separated parts
and if the part has an ".py" extension
- don't use py.std import helper, rather import things directly.
Thanks Bruno Oliveira.
2.6
-----------------------------------
- Cache exceptions from fixtures according to their scope (issue 467).
- fix issue537: Avoid importing old assertion reinterpretation code by default.
- fix issue364: shorten and enhance tracebacks representation by default.
The new "--tb=auto" option (default) will only display long tracebacks
for the first and last entry. You can get the old behaviour of printing
all entries as long entries with "--tb=long". Also short entries by
default are now printed very similarly to "--tb=native" ones.
- fix issue514: teach assertion reinterpretation about private class attributes
- change -v output to include full node IDs of tests. Users can copy
a node ID from a test run, including line number, and use it as a
positional argument in order to run only a single test.
- fix issue 475: fail early and comprehensible if calling
pytest.raises with wrong exception type.
- fix issue516: tell in getting-started about current dependencies.
- cleanup setup.py a bit and specify supported versions. Thanks Jurko
Gospodnetic for the PR.
- change XPASS colour to yellow rather then red when tests are run
with -v.
- fix issue473: work around mock putting an unbound method into a class
dict when double-patching.
- fix issue498: if a fixture finalizer fails, make sure that
the fixture is still invalidated.
- fix issue453: the result of the pytest_assertrepr_compare hook now gets
it's newlines escaped so that format_exception does not blow up.
- internal new warning system: pytest will now produce warnings when
it detects oddities in your test collection or execution.
Warnings are ultimately sent to a new pytest_logwarning hook which is
currently only implemented by the terminal plugin which displays
warnings in the summary line and shows more details when -rw (report on
warnings) is specified.
- change skips into warnings for test classes with an __init__ and
callables in test modules which look like a test but are not functions.
- fix issue436: improved finding of initial conftest files from command
line arguments by using the result of parse_known_args rather than
the previous flaky heuristics. Thanks Marc Abramowitz for tests
and initial fixing approaches in this area.
- fix issue #479: properly handle nose/unittest(2) SkipTest exceptions
during collection/loading of test modules. Thanks to Marc Schlaich
for the complete PR.
- fix issue490: include pytest_load_initial_conftests in documentation
and improve docstring.
- fix issue472: clarify that ``pytest.config.getvalue()`` cannot work
if it's triggered ahead of command line parsing.
- merge PR123: improved integration with mock.patch decorator on tests.
- fix issue412: messing with stdout/stderr FD-level streams is now
captured without crashes.
- fix issue483: trial/py33 works now properly. Thanks Daniel Grana for PR.
- improve example for pytest integration with "python setup.py test"
which now has a generic "-a" or "--pytest-args" option where you
can pass additional options as a quoted string. Thanks Trevor Bekolay.
- simplified internal capturing mechanism and made it more robust
against tests or setups changing FD1/FD2, also better integrated
now with pytest.pdb() in single tests.
- improvements to pytest's own test-suite leakage detection, courtesy of PRs
from Marc Abramowitz
- fix issue492: avoid leak in test_writeorg. Thanks Marc Abramowitz.
- fix issue493: don't run tests in doc directory with ``python setup.py test``
(use tox -e doctesting for that)
- fix issue486: better reporting and handling of early conftest loading failures
- some cleanup and simplification of internal conftest handling.
- work a bit harder to break reference cycles when catching exceptions.
Thanks Jurko Gospodnetic.
- fix issue443: fix skip examples to use proper comparison. Thanks Alex
Groenholm.
- support nose-style ``__test__`` attribute on modules, classes and
functions, including unittest-style Classes. If set to False, the
test will not be collected.
- fix issue512: show "<notset>" for arguments which might not be set
in monkeypatch plugin. Improves output in documentation.
2.5.2
-----------------------------------
- fix issue409 -- better interoperate with cx_freeze by not
trying to import from collections.abc which causes problems
for py27/cx_freeze. Thanks Wolfgang L. for reporting and tracking it down.
- fixed docs and code to use "pytest" instead of "py.test" almost everywhere.
Thanks Jurko Gospodnetic for the complete PR.
- fix issue425: mention at end of "py.test -h" that --markers
and --fixtures work according to specified test path (or current dir)
- fix issue413: exceptions with unicode attributes are now printed
correctly also on python2 and with pytest-xdist runs. (the fix
requires py-1.4.20)
- copy, cleanup and integrate py.io capture
from pylib 1.4.20.dev2 (rev 13d9af95547e)
- address issue416: clarify docs as to conftest.py loading semantics
- fix issue429: comparing byte strings with non-ascii chars in assert
expressions now work better. Thanks Floris Bruynooghe.
- make capfd/capsys.capture private, its unused and shouldnt be exposed
2.5.1
-----------------------------------

171
CONTRIBUTING.rst Normal file
View File

@@ -0,0 +1,171 @@
============
Contributing
============
Contributions are highly welcomed and appreciated. Every little help counts,
so do not hesitate!
Types of contributions
======================
Report bugs
-----------
Report bugs at https://bitbucket.org/hpk42/pytest/issues.
If you are reporting a bug, please include:
* Your operating system name and version.
* Any details about your local setup that might be helpful in troubleshooting,
specifically Python interpreter version,
installed libraries and pytest version.
* Detailed steps to reproduce the bug.
Submit feedback for developers
------------------------------
Do you like pytest? Share some love on Twitter or in your blog posts!
We'd also like to hear about your propositions and suggestions. Feel free to
`submit them as issues <https://bitbucket.org/hpk42/pytest/issues>`__ and:
* Set the "kind" to "enhancement" or "proposal" so that we can quickly find
about them.
* Explain in detail how they should work.
* Keep the scope as narrow as possible. This will make it easier to implement.
* If you have required skills and/or knowledge, we are very happy for
:ref:`pull requests <pull-requests>`.
Fix bugs
--------
Look through the BitBucket issues for bugs. Here is sample filter you can use:
https://bitbucket.org/hpk42/pytest/issues?status=new&status=open&kind=bug
:ref:`Talk <contact>` to developers to find out how you can fix specific bugs.
Implement features
------------------
Look through the BitBucket issues for enhancements. Here is sample filter you
can use:
https://bitbucket.org/hpk42/pytest/issues?status=new&status=open&kind=enhancement
:ref:`Talk <contact>` to developers to find out how you can implement specific
features.
Write documentation
-------------------
pytest could always use more documentation. What exactly is needed?
* More complementary documentation. Have you perhaps found something unclear?
* Documentation translations. We currently have English and Japanese versions.
* Docstrings. There's never too much of them.
* Blog posts, articles and such -- they're all very appreciated.
.. _pull-requests:
Preparing Pull Requests on Bitbucket
=====================================
.. note::
What is a "pull request"? It informs project's core developers about the
changes you want to review and merge. Pull requests are stored on
`BitBucket servers <https://bitbucket.org/hpk42/pytest/pull-requests>`__.
Once you send pull request, we can discuss it's potential modifications and
even add more commits to it later on.
The primary development platform for pytest is BitBucket. You can find all
the issues there and submit your pull requests.
1. Fork the
`pytest BitBucket repository <https://bitbucket.org/hpk42/pytest>`__. It's
fine to use ``pytest`` as your fork repository name because it will live
under your user.
.. _virtualenvactivate:
2. Create and activate a fork-specific virtualenv
(http://www.virtualenv.org/en/latest/)::
$ virtualenv pytest-venv
$ source pytest-venv/bin/activate
.. _checkout:
3. Clone your fork locally using `Mercurial <http://mercurial.selenic.com/>`_
(``hg``) and create a branch::
$ hg clone ssh://hg@bitbucket.org/YOUR_BITBUCKET_USERNAME/pytest
$ cd pytest
$ hg branch your-branch-name
If you need some help with Mercurial, follow this quick start
guide: http://mercurial.selenic.com/wiki/QuickStart
.. _testing-pytest:
4. You can now edit your local working copy. To test you need to
install the "tox" tool into your virtualenv::
$ pip install tox
You need to have Python 2.7 and 3.3 available in your system. Now
running tests is as simple as issuing this command::
$ python runtox.py -e py27,py33,flakes
This command will run tests via the "tox" tool against Python 2.7 and 3.3
and also perform "flakes" coding-style checks. ``runtox.py`` is
a thin wrapper around ``tox`` which installs from a development package
index where newer (not yet released to pypi) versions of dependencies
(especially ``py``) might be present.
To run tests on py27 and pass options (e.g. enter pdb on failure)
to pytest you can do::
$ python runtox.py -e py27 -- --pdb
or to only run tests in a particular test module on py33::
$ python runtox.py -e py33 -- testing/test_config.py
5. Commit and push once your tests pass and you are happy with your change(s)::
$ hg commit -m"<commit message>"
$ hg push -b .
6. Finally, submit a pull request through the BitBucket website:
.. image:: img/pullrequest.png
:width: 700px
:align: center
::
source: YOUR_BITBUCKET_USERNAME/pytest
branch: your-branch-name
target: hpk42/pytest
branch: default
.. _contribution-using-git:
What about git (and so GitHub)?
-------------------------------
There used to be the pytest GitHub mirror. It was removed in favor of the
Mercurial one, to remove confusion of people not knowing where it's better to
put their issues and pull requests. Also it wasn't easily possible to automate
the mirroring process.
However, it's still possible to use git to contribute to pytest using tools
like `gitifyhg <https://github.com/buchuki/gitifyhg>`_ which allows you to
clone and work with Mercurial repo still using git.
.. warning::
Remember that git is **not** a default version control system for pytest and
you need to be careful using it.

44
HOWTORELEASE.rst Normal file
View File

@@ -0,0 +1,44 @@
How to release pytest (draft)
--------------------------------------------
1. bump version numbers in setup.py and pytest/__init__.py
2. check and finalize CHANGELOG
3. write doc/en/announce/pytest-VERSION.txt and include
it in doc/en/announce/index.txt
4. use devpi for uploading a release tarball to a staging area:
- ``devpi use https://devpi.net/USER/dev``
- ``devpi upload``
5. run from multiple machines:
- ``devpi use https://devpi.net/USER/dev``
- ``devpi test pytest-VERSION``
6. check that tests pass for relevant combinations with
``devpi list pytest``
or look at failures with "devpi list -f pytest".
There will be some failed environments like e.g. the py33-trial
or py27-pexpect tox environments on Win32 platforms
which is ok (tox does not support skipping on
per-platform basis yet).
7. go to "doc/en" and upload docs with "make install"
(the latter requires ssh-login permissions on pytest.org
because it uses rsync). Note that the "install" target of
doc/en/Makefile defines where the rsync goes to, typically
to the "latest" section of pytest.org.
8. publish to pypi "devpi push pytest-2.6.2 pypi:NAME" where NAME
is the name of pypi.python.org as configured in your
~/.pypirc file -- it's the same you would use with
"setup.py upload -r NAME"
9. send release announcement to mailing lists:
pytest-dev
testing-in-python
python-announce-list@python.org

View File

@@ -79,15 +79,6 @@ style tests, i.e. it leverages existing test suites without needing
to rewrite them. Together with the previously mentioned setup_test()
maybe the setupfunc could be ommitted?
checks / deprecations for next release
---------------------------------------------------------------
tags: bug 2.4 core xdist
* check oejskit plugin compatibility
* move pytest_nose out of pylib because it implicitely extends
the protocol now - setup/teardown is called at module level.
consider making calling of setup/teardown configurable
optimizations
---------------------------------------------------------------
tags: 2.4 core
@@ -122,8 +113,8 @@ customize test function collection
-------------------------------------------------------
tags: feature
- introduce py.test.mark.nocollect for not considering a function for
test collection at all. maybe also introduce a py.test.mark.test to
- introduce pytest.mark.nocollect for not considering a function for
test collection at all. maybe also introduce a pytest.mark.test to
explicitely mark a function to become a tested one. Lookup JUnit ways
of tagging tests.
@@ -135,18 +126,18 @@ in addition to the imperative pytest.importorskip also introduce
a pytest.mark.importorskip so that the test count is more correct.
introduce py.test.mark.platform
introduce pytest.mark.platform
-------------------------------------------------------
tags: feature
Introduce nice-to-spell platform-skipping, examples:
@py.test.mark.platform("python3")
@py.test.mark.platform("not python3")
@py.test.mark.platform("win32 and not python3")
@py.test.mark.platform("darwin")
@py.test.mark.platform("not (jython and win32)")
@py.test.mark.platform("not (jython and win32)", xfail=True)
@pytest.mark.platform("python3")
@pytest.mark.platform("not python3")
@pytest.mark.platform("win32 and not python3")
@pytest.mark.platform("darwin")
@pytest.mark.platform("not (jython and win32)")
@pytest.mark.platform("not (jython and win32)", xfail=True)
etc. Idea is to allow Python expressions which can operate
on common spellings for operating systems and python
@@ -181,8 +172,8 @@ tags: feature
allow to name conftest.py files (in sub directories) that should
be imported early, as to include command line options.
improve central py.test ini file
----------------------------------
improve central pytest ini file
-------------------------------
tags: feature
introduce more declarative configuration options:
@@ -196,7 +187,7 @@ new documentation
----------------------------------
tags: feature
- logo py.test
- logo pytest
- examples for unittest or functional testing
- resource management for functional testing
- patterns: page object
@@ -205,17 +196,17 @@ have imported module mismatch honour relative paths
--------------------------------------------------------
tags: bug
With 1.1.1 py.test fails at least on windows if an import
With 1.1.1 pytest fails at least on windows if an import
is relative and compared against an absolute conftest.py
path. Normalize.
consider globals: py.test.ensuretemp and config
consider globals: pytest.ensuretemp and config
--------------------------------------------------------------
tags: experimental-wish
consider deprecating py.test.ensuretemp and py.test.config
to further reduce py.test globality. Also consider
having py.test.config and ensuretemp coming from
consider deprecating pytest.ensuretemp and pytest.config
to further reduce pytest globality. Also consider
having pytest.config and ensuretemp coming from
a plugin rather than being there from the start.
@@ -223,7 +214,7 @@ consider pytest_addsyspath hook
-----------------------------------------
tags: wish
py.test could call a new pytest_addsyspath() in order to systematically
pytest could call a new pytest_addsyspath() in order to systematically
allow manipulation of sys.path and to inhibit it via --no-addsyspath
in order to more easily run against installed packages.
@@ -232,11 +223,11 @@ and pytest_configure.
deprecate global py.test.config usage
deprecate global pytest.config usage
----------------------------------------------------------------
tags: feature
py.test.ensuretemp and py.test.config are probably the last
pytest.ensuretemp and pytest.config are probably the last
objects containing global state. Often using them is not
neccessary. This is about trying to get rid of them, i.e.
deprecating them and checking with PyPy's usages as well

View File

@@ -5,7 +5,9 @@ Changelog: http://pytest.org/latest/changelog.html
Issues: https://bitbucket.org/hpk42/pytest/issues?status=open
The ``py.test`` testing tool makes it easy to write small tests, yet
CI: https://drone.io/bitbucket.org/hpk42/pytest
The ``pytest`` testing tool makes it easy to write small tests, yet
scales to support complex functional testing. It provides
- `auto-discovery
@@ -14,17 +16,14 @@ scales to support complex functional testing. It provides
- detailed info on failing `assert statements <http://pytest.org/latest/assert.html>`_ (no need to remember ``self.assert*`` names)
- `modular fixtures <http://pytest.org/latest/fixture.html>`_ for
managing small or parametrized long-lived test resources.
- multi-paradigm support: you can use ``py.test`` to run test suites based
- multi-paradigm support: you can use ``pytest`` to run test suites based
on `unittest <http://pytest.org/latest/unittest.html>`_ (or trial),
`nose <http://pytest.org/latest/nose.html>`_
- single-source compatibility to Python2.4 all the way up to Python3.3,
PyPy-1.9 and Jython-2.5.1.
- single-source compatibility to Python2.5 all the way up to Python3.4,
PyPy-2.3 and Jython-2.5.1.
- many `external plugins <http://pytest.org/latest/plugins.html#installing-external-plugins-searching>`_.
.. image:: https://secure.travis-ci.org/hpk42/pytest.png
:target: http://travis-ci.org/hpk42/pytest
A simple example for a test::
# content of test_module.py
@@ -42,11 +41,10 @@ and report bugs at:
http://bitbucket.org/hpk42/pytest/issues/
and checkout repos at:
and checkout or fork repo at:
http://github.com/hpk42/pytest/ (mirror)
http://bitbucket.org/hpk42/pytest/
Copyright Holger Krekel and others, 2004-2013
Copyright Holger Krekel and others, 2004-2014
Licensed under the MIT license.

View File

@@ -1,2 +1,2 @@
#
__version__ = '2.5.1'
__version__ = '2.6.2'

View File

@@ -6,20 +6,32 @@ import sys
from _pytest.monkeypatch import monkeypatch
from _pytest.assertion import util
def pytest_addoption(parser):
group = parser.getgroup("debugconfig")
group.addoption('--assert', action="store", dest="assertmode",
group.addoption('--assert',
action="store",
dest="assertmode",
choices=("rewrite", "reinterp", "plain",),
default="rewrite", metavar="MODE",
help="""control assertion debugging tools.
'plain' performs no assertion debugging.
'reinterp' reinterprets assert statements after they failed to provide assertion expression information.
'rewrite' (the default) rewrites assert statements in test modules on import
to provide assert expression information. """)
group.addoption('--no-assert', action="store_true", default=False,
dest="noassert", help="DEPRECATED equivalent to --assert=plain")
group.addoption('--nomagic', '--no-magic', action="store_true",
default=False, help="DEPRECATED equivalent to --assert=plain")
default="rewrite",
metavar="MODE",
help="""control assertion debugging tools. 'plain'
performs no assertion debugging. 'reinterp'
reinterprets assert statements after they failed
to provide assertion expression information.
'rewrite' (the default) rewrites assert
statements in test modules on import to
provide assert expression information. """)
group.addoption('--no-assert',
action="store_true",
default=False,
dest="noassert",
help="DEPRECATED equivalent to --assert=plain")
group.addoption('--nomagic', '--no-magic',
action="store_true",
default=False,
help="DEPRECATED equivalent to --assert=plain")
class AssertionState:
"""State for the assertion plugin."""
@@ -28,6 +40,7 @@ class AssertionState:
self.mode = mode
self.trace = config.trace.root.get("assertion")
def pytest_configure(config):
mode = config.getvalue("assertmode")
if config.getvalue("noassert") or config.getvalue("nomagic"):
@@ -41,7 +54,7 @@ def pytest_configure(config):
# Both Jython and CPython 2.6.0 have AST bugs that make the
# assertion rewriting hook malfunction.
if (sys.platform.startswith('java') or
sys.version_info[:3] == (2, 6, 0)):
sys.version_info[:3] == (2, 6, 0)):
mode = "reinterp"
if mode != "plain":
_load_modules(mode)
@@ -58,11 +71,13 @@ def pytest_configure(config):
config._assertstate.hook = hook
config._assertstate.trace("configured with mode set to %r" % (mode,))
def pytest_unconfigure(config):
hook = config._assertstate.hook
if hook is not None:
if hook is not None and hook in sys.meta_path:
sys.meta_path.remove(hook)
def pytest_collection(session):
# this hook is only called when test modules are collected
# so for example not in the master process of pytest-xdist
@@ -71,36 +86,55 @@ def pytest_collection(session):
if hook is not None:
hook.set_session(session)
def pytest_runtest_setup(item):
"""Setup the pytest_assertrepr_compare hook
The newinterpret and rewrite modules will use util._reprcompare if
it exists to use custom reporting via the
pytest_assertrepr_compare hook. This sets up this custom
comparison for the test.
"""
def callbinrepr(op, left, right):
"""Call the pytest_assertrepr_compare hook and prepare the result
This uses the first result from the hook and then ensures the
following:
* Overly verbose explanations are dropped unles -vv was used.
* Embedded newlines are escaped to help util.format_explanation()
later.
* If the rewrite mode is used embedded %-characters are replaced
to protect later % formatting.
The result can be formatted by util.format_explanation() for
pretty printing.
"""
hook_result = item.ihook.pytest_assertrepr_compare(
config=item.config, op=op, left=left, right=right)
for new_expl in hook_result:
if new_expl:
# Don't include pageloads of data unless we are very
# verbose (-vv)
if (len(py.builtin._totext('').join(new_expl[1:])) > 80*8
if (sum(len(p) for p in new_expl[1:]) > 80*8
and item.config.option.verbose < 2):
new_expl[1:] = [py.builtin._totext(
'Detailed information truncated, use "-vv" to see')]
res = py.builtin._totext('\n~').join(new_expl)
'Detailed information truncated, use "-vv" to show')]
new_expl = [line.replace("\n", "\\n") for line in new_expl]
res = py.builtin._totext("\n~").join(new_expl)
if item.config.getvalue("assertmode") == "rewrite":
# The result will be fed back a python % formatting
# operation, which will fail if there are extraneous
# '%'s in the string. Escape them here.
res = res.replace("%", "%%")
return res
util._reprcompare = callbinrepr
def pytest_runtest_teardown(item):
util._reprcompare = None
def pytest_sessionfinish(session):
hook = session.config._assertstate.hook
if hook is not None:
hook.session = None
def _load_modules(mode):
"""Lazily import assertion related code."""
global rewrite, reinterpret
@@ -108,6 +142,7 @@ def _load_modules(mode):
if mode == "rewrite":
from _pytest.assertion import rewrite # noqa
def warn_about_missing_assertion(mode):
try:
assert False
@@ -121,8 +156,10 @@ def warn_about_missing_assertion(mode):
specifically = "failing tests may report as passing"
sys.stderr.write("WARNING: " + specifically +
" because assert statements are not executed "
"by the underlying Python interpreter "
"(are you using python -O?)\n")
" because assert statements are not executed "
"by the underlying Python interpreter "
"(are you using python -O?)\n")
# Expose this plugin's implementation for the pytest_assertrepr_compare hook
pytest_assertrepr_compare = util.assertrepr_compare

View File

@@ -286,7 +286,19 @@ class DebugInterpreter(ast.NodeVisitor):
source = "__exprinfo_expr.%s" % (attr.attr,)
co = self._compile(source)
try:
result = self.frame.eval(co, __exprinfo_expr=source_result)
try:
result = self.frame.eval(co, __exprinfo_expr=source_result)
except AttributeError:
# Maybe the attribute name needs to be mangled?
if not attr.attr.startswith("__") or attr.attr.endswith("__"):
raise
source = "getattr(__exprinfo_expr.__class__, '__name__', '')"
co = self._compile(source)
class_name = self.frame.eval(co, __exprinfo_expr=source_result)
mangled_attr = "_" + class_name + attr.attr
source = "__exprinfo_expr.%s" % (mangled_attr,)
co = self._compile(source)
result = self.frame.eval(co, __exprinfo_expr=source_result)
except Exception:
raise Failure(explanation)
explanation = "%s\n{%s = %s.%s\n}" % (self.frame.repr(result),

View File

@@ -1,3 +1,5 @@
import traceback
import types
import py
import sys, inspect
from compiler import parse, ast, pycodegen
@@ -355,7 +357,18 @@ class Getattr(Interpretable):
expr.eval(frame)
source = '__exprinfo_expr.%s' % self.attrname
try:
self.result = frame.eval(source, __exprinfo_expr=expr.result)
try:
self.result = frame.eval(source, __exprinfo_expr=expr.result)
except AttributeError:
# Maybe the attribute name needs to be mangled?
if (not self.attrname.startswith("__") or
self.attrname.endswith("__")):
raise
source = "getattr(__exprinfo_expr.__class__, '__name__', '')"
class_name = frame.eval(source, __exprinfo_expr=expr.result)
mangled_attr = "_" + class_name + self.attrname
source = "__exprinfo_expr.%s" % (mangled_attr,)
self.result = frame.eval(source, __exprinfo_expr=expr.result)
except passthroughex:
raise
except:
@@ -466,7 +479,7 @@ def check(s, frame=None):
def interpret(source, frame, should_fail=False):
module = Interpretable(parse(source, 'exec').node)
#print "got module", module
if isinstance(frame, py.std.types.FrameType):
if isinstance(frame, types.FrameType):
frame = py.code.Frame(frame)
try:
module.run(frame)
@@ -476,7 +489,6 @@ def interpret(source, frame, should_fail=False):
except passthroughex:
raise
except:
import traceback
traceback.print_exc()
if should_fail:
return ("(assertion failed, but when it was re-run for "

View File

@@ -45,10 +45,8 @@ class AssertionError(BuiltinAssertionError):
if sys.version_info > (3, 0):
AssertionError.__module__ = "builtins"
reinterpret_old = "old reinterpretation not available for py3"
else:
from _pytest.assertion.oldinterpret import interpret as reinterpret_old
if sys.version_info >= (2, 6) or (sys.platform.startswith("java")):
if sys.version_info >= (2, 6) or sys.platform.startswith("java"):
from _pytest.assertion.newinterpret import interpret as reinterpret
else:
reinterpret = reinterpret_old
from _pytest.assertion.oldinterpret import interpret as reinterpret

View File

@@ -15,7 +15,7 @@ import py
from _pytest.assertion import util
# py.test caches rewritten pycs in __pycache__.
# pytest caches rewritten pycs in __pycache__.
if hasattr(imp, "get_tag"):
PYTEST_TAG = imp.get_tag() + "-PYTEST"
else:
@@ -102,7 +102,7 @@ class AssertionRewritingHook(object):
# the most magical part of the process: load the source, rewrite the
# asserts, and load the rewritten source. We also cache the rewritten
# module code in a special pyc. We must be aware of the possibility of
# concurrent py.test processes rewriting and loading pycs. To avoid
# concurrent pytest processes rewriting and loading pycs. To avoid
# tricky race conditions, we maintain the following invariant: The
# cached pyc is always a complete, valid pyc. Operations on it must be
# atomic. POSIX's atomic rename comes in handy.
@@ -131,15 +131,15 @@ class AssertionRewritingHook(object):
pyc = os.path.join(cache_dir, cache_name)
# Notice that even if we're in a read-only directory, I'm going
# to check for a cached pyc. This may not be optimal...
co = _read_pyc(fn_pypath, pyc)
co = _read_pyc(fn_pypath, pyc, state.trace)
if co is None:
state.trace("rewriting %r" % (fn,))
co = _rewrite_test(state, fn_pypath)
source_stat, co = _rewrite_test(state, fn_pypath)
if co is None:
# Probably a SyntaxError in the test.
return None
if write:
_make_rewritten_pyc(state, fn_pypath, pyc, co)
_make_rewritten_pyc(state, source_stat, pyc, co)
else:
state.trace("found cached rewritten pyc for %r" % (fn,))
self.modules[name] = co, pyc
@@ -192,13 +192,12 @@ class AssertionRewritingHook(object):
pkg_resources.register_loader_type(cls, pkg_resources.DefaultProvider)
def _write_pyc(state, co, source_path, pyc):
def _write_pyc(state, co, source_stat, pyc):
# Technically, we don't have to have the same pyc format as
# (C)Python, since these "pycs" should never be seen by builtin
# import. However, there's little reason deviate, and I hope
# sometime to be able to use imp.load_compiled to load them. (See
# the comment in load_module above.)
mtime = int(source_path.mtime())
try:
fp = open(pyc, "wb")
except IOError:
@@ -210,7 +209,9 @@ def _write_pyc(state, co, source_path, pyc):
return False
try:
fp.write(imp.get_magic())
fp.write(struct.pack("<l", mtime))
mtime = int(source_stat.mtime)
size = source_stat.size & 0xFFFFFFFF
fp.write(struct.pack("<ll", mtime, size))
marshal.dump(co, fp)
finally:
fp.close()
@@ -225,9 +226,10 @@ BOM_UTF8 = '\xef\xbb\xbf'
def _rewrite_test(state, fn):
"""Try to read and rewrite *fn* and return the code object."""
try:
stat = fn.stat()
source = fn.read("rb")
except EnvironmentError:
return None
return None, None
if ASCII_IS_DEFAULT_ENCODING:
# ASCII is the default encoding in Python 2. Without a coding
# declaration, Python 2 will complain about any bytes in the file
@@ -246,14 +248,15 @@ def _rewrite_test(state, fn):
cookie_re.match(source[0:end1]) is None and
cookie_re.match(source[end1 + 1:end2]) is None):
if hasattr(state, "_indecode"):
return None # encodings imported us again, we don't rewrite
# encodings imported us again, so don't rewrite.
return None, None
state._indecode = True
try:
try:
source.decode("ascii")
except UnicodeDecodeError:
# Let it fail in real import.
return None
return None, None
finally:
del state._indecode
# On Python versions which are not 2.7 and less than or equal to 3.1, the
@@ -265,7 +268,7 @@ def _rewrite_test(state, fn):
except SyntaxError:
# Let this pop up again in the real import.
state.trace("failed to parse: %r" % (fn,))
return None
return None, None
rewrite_asserts(tree)
try:
co = compile(tree, fn.strpath, "exec")
@@ -273,24 +276,24 @@ def _rewrite_test(state, fn):
# It's possible that this error is from some bug in the
# assertion rewriting, but I don't know of a fast way to tell.
state.trace("failed to compile: %r" % (fn,))
return None
return co
return None, None
return stat, co
def _make_rewritten_pyc(state, fn, pyc, co):
def _make_rewritten_pyc(state, source_stat, pyc, co):
"""Try to dump rewritten code to *pyc*."""
if sys.platform.startswith("win"):
# Windows grants exclusive access to open files and doesn't have atomic
# rename, so just write into the final file.
_write_pyc(state, co, fn, pyc)
_write_pyc(state, co, source_stat, pyc)
else:
# When not on windows, assume rename is atomic. Dump the code object
# into a file specific to this process and atomically replace it.
proc_pyc = pyc + "." + str(os.getpid())
if _write_pyc(state, co, fn, proc_pyc):
if _write_pyc(state, co, source_stat, proc_pyc):
os.rename(proc_pyc, pyc)
def _read_pyc(source, pyc):
"""Possibly read a py.test pyc containing rewritten code.
def _read_pyc(source, pyc, trace=lambda x: None):
"""Possibly read a pytest pyc containing rewritten code.
Return rewritten code if successful or None if not.
"""
@@ -298,23 +301,28 @@ def _read_pyc(source, pyc):
fp = open(pyc, "rb")
except IOError:
return None
try:
with fp:
try:
mtime = int(source.mtime())
data = fp.read(8)
except EnvironmentError:
size = source.size()
data = fp.read(12)
except EnvironmentError as e:
trace('_read_pyc(%s): EnvironmentError %s' % (source, e))
return None
# Check for invalid or out of date pyc file.
if (len(data) != 8 or data[:4] != imp.get_magic() or
struct.unpack("<l", data[4:])[0] != mtime):
if (len(data) != 12 or data[:4] != imp.get_magic() or
struct.unpack("<ll", data[4:]) != (mtime, size)):
trace('_read_pyc(%s): invalid or out of date pyc' % source)
return None
try:
co = marshal.load(fp)
except Exception as e:
trace('_read_pyc(%s): marshal.load error %s' % (source, e))
return None
co = marshal.load(fp)
if not isinstance(co, types.CodeType):
# That's interesting....
trace('_read_pyc(%s): not a code object' % source)
return None
return co
finally:
fp.close()
def rewrite_asserts(mod):
@@ -322,7 +330,25 @@ def rewrite_asserts(mod):
AssertionRewriter().run(mod)
_saferepr = py.io.saferepr
def _saferepr(obj):
"""Get a safe repr of an object for assertion error messages.
The assertion formatting (util.format_explanation()) requires
newlines to be escaped since they are a special character for it.
Normally assertion.util.format_explanation() does this but for a
custom repr it is possible to contain one of the special escape
sequences, especially '\n{' and '\n}' are likely to be present in
JSON reprs.
"""
repr = py.io.saferepr(obj)
if py.builtin._istext(repr):
t = py.builtin.text
else:
t = py.builtin.bytes
return repr.replace(t("\n"), t("\\n"))
from _pytest.assertion.util import format_explanation as _format_explanation # noqa
def _should_repr_global_name(obj):

View File

@@ -1,14 +1,11 @@
"""Utilities for assertion debugging"""
import pprint
import py
try:
from collections.abc import Sequence
from collections import Sequence
except ImportError:
try:
from collections import Sequence
except ImportError:
Sequence = list
Sequence = list
BuiltinAssertionError = py.builtin.builtins.AssertionError
u = py.builtin._totext
@@ -153,11 +150,10 @@ def assertrepr_compare(config, op, left, right):
if istext(left) and istext(right):
explanation = _notin_text(left, right, verbose)
except Exception:
excinfo = py.code.ExceptionInfo()
explanation = [
u('(pytest_assertion plugin: representation of details failed. '
'Probably an object has a faulty __repr__.)'),
u(excinfo)]
u(py.code.ExceptionInfo())]
if not explanation:
return None
@@ -166,12 +162,19 @@ def assertrepr_compare(config, op, left, right):
def _diff_text(left, right, verbose=False):
"""Return the explanation for the diff between text
"""Return the explanation for the diff between text or bytes
Unless --verbose is used this will skip leading and trailing
characters which are identical to keep the diff minimal.
If the input are bytes they will be safely converted to text.
"""
from difflib import ndiff
explanation = []
if isinstance(left, py.builtin.bytes):
left = u(repr(left)[1:-1]).replace(r'\n', '\n')
if isinstance(right, py.builtin.bytes):
right = u(repr(right)[1:-1]).replace(r'\n', '\n')
if not verbose:
i = 0 # just in case left or right has zero length
for i in range(min(len(left), len(right))):
@@ -194,8 +197,8 @@ def _diff_text(left, right, verbose=False):
left = left[:-i]
right = right[:-i]
explanation += [line.strip('\n')
for line in py.std.difflib.ndiff(left.splitlines(),
right.splitlines())]
for line in ndiff(left.splitlines(),
right.splitlines())]
return explanation
@@ -213,8 +216,8 @@ def _compare_eq_sequence(left, right, verbose=False):
explanation += [
u('Right contains more items, first extra item: %s') %
py.io.saferepr(right[len(left)],)]
return explanation # + _diff_text(py.std.pprint.pformat(left),
# py.std.pprint.pformat(right))
return explanation # + _diff_text(pprint.pformat(left),
# pprint.pformat(right))
def _compare_eq_set(left, right, verbose=False):
@@ -241,7 +244,7 @@ def _compare_eq_dict(left, right, verbose=False):
len(same)]
elif same:
explanation += [u('Common items:')]
explanation += py.std.pprint.pformat(same).splitlines()
explanation += pprint.pformat(same).splitlines()
diff = set(k for k in common if left[k] != right[k])
if diff:
explanation += [u('Differing items:')]
@@ -251,12 +254,12 @@ def _compare_eq_dict(left, right, verbose=False):
extra_left = set(left) - set(right)
if extra_left:
explanation.append(u('Left contains more items:'))
explanation.extend(py.std.pprint.pformat(
explanation.extend(pprint.pformat(
dict((k, left[k]) for k in extra_left)).splitlines())
extra_right = set(right) - set(left)
if extra_right:
explanation.append(u('Right contains more items:'))
explanation.extend(py.std.pprint.pformat(
explanation.extend(pprint.pformat(
dict((k, right[k]) for k in extra_right)).splitlines())
return explanation

View File

@@ -1,42 +1,52 @@
""" per-test stdout/stderr capturing mechanisms, ``capsys`` and ``capfd`` function arguments. """
"""
per-test stdout/stderr capturing mechanism.
"""
from __future__ import with_statement
import pytest, py
import sys
import os
from tempfile import TemporaryFile
import py
import pytest
from py.io import TextIO
unicode = py.builtin.text
patchsysdict = {0: 'stdin', 1: 'stdout', 2: 'stderr'}
def pytest_addoption(parser):
group = parser.getgroup("general")
group._addoption('--capture', action="store", default=None,
group._addoption(
'--capture', action="store",
default="fd" if hasattr(os, "dup") else "sys",
metavar="method", choices=['fd', 'sys', 'no'],
help="per-test capturing method: one of fd (default)|sys|no.")
group._addoption('-s', action="store_const", const="no", dest="capture",
help="per-test capturing method: one of fd|sys|no.")
group._addoption(
'-s', action="store_const", const="no", dest="capture",
help="shortcut for --capture=no.")
@pytest.mark.tryfirst
def pytest_load_initial_conftests(early_config, parser, args, __multicall__):
ns = parser.parse_known_args(args)
method = ns.capture
if not method:
method = "fd"
if method == "fd" and not hasattr(os, "dup"):
method = "sys"
capman = CaptureManager(method)
early_config.pluginmanager.register(capman, "capturemanager")
ns = early_config.known_args_namespace
pluginmanager = early_config.pluginmanager
capman = CaptureManager(ns.capture)
pluginmanager.register(capman, "capturemanager")
# make sure that capturemanager is properly reset at final shutdown
def teardown():
try:
capman.reset_capturings()
except ValueError:
pass
early_config.pluginmanager.add_shutdown(teardown)
pluginmanager.add_shutdown(capman.reset_capturings)
# make sure logging does not raise exceptions at the end
def silence_logging_at_shutdown():
if "logging" in sys.modules:
sys.modules["logging"].raiseExceptions = False
early_config.pluginmanager.add_shutdown(silence_logging_at_shutdown)
pluginmanager.add_shutdown(silence_logging_at_shutdown)
# finally trigger conftest loading but while capturing (issue93)
capman.resumecapture()
capman.init_capturings()
try:
try:
return __multicall__.execute()
@@ -47,202 +57,388 @@ def pytest_load_initial_conftests(early_config, parser, args, __multicall__):
sys.stderr.write(err)
raise
def addouterr(rep, outerr):
for secname, content in zip(["out", "err"], outerr):
if content:
rep.sections.append(("Captured std%s" % secname, content))
class NoCapture:
def startall(self):
pass
def resume(self):
pass
def reset(self):
pass
def suspend(self):
return "", ""
class CaptureManager:
def __init__(self, defaultmethod=None):
self._method2capture = {}
self._defaultmethod = defaultmethod
def _maketempfile(self):
f = py.std.tempfile.TemporaryFile()
newf = py.io.dupfile(f, encoding="UTF-8")
f.close()
return newf
def _makestringio(self):
return py.io.TextIO()
def __init__(self, method):
self._method = method
def _getcapture(self, method):
if method == "fd":
return py.io.StdCaptureFD(now=False,
out=self._maketempfile(), err=self._maketempfile()
)
return MultiCapture(out=True, err=True, Capture=FDCapture)
elif method == "sys":
return py.io.StdCapture(now=False,
out=self._makestringio(), err=self._makestringio()
)
return MultiCapture(out=True, err=True, Capture=SysCapture)
elif method == "no":
return NoCapture()
return MultiCapture(out=False, err=False, in_=False)
else:
raise ValueError("unknown capturing method: %r" % method)
def _getmethod(self, config, fspath):
if config.option.capture:
method = config.option.capture
else:
try:
method = config._conftest.rget("option_capture", path=fspath)
except KeyError:
method = "fd"
if method == "fd" and not hasattr(os, 'dup'): # e.g. jython
method = "sys"
return method
def init_capturings(self):
assert not hasattr(self, "_capturing")
self._capturing = self._getcapture(self._method)
self._capturing.start_capturing()
def reset_capturings(self):
for name, cap in self._method2capture.items():
cap.reset()
cap = self.__dict__.pop("_capturing", None)
if cap is not None:
cap.pop_outerr_to_orig()
cap.stop_capturing()
def resumecapture_item(self, item):
method = self._getmethod(item.config, item.fspath)
if not hasattr(item, 'outerr'):
item.outerr = ('', '') # we accumulate outerr on the item
return self.resumecapture(method)
def resumecapture(self):
self._capturing.resume_capturing()
def resumecapture(self, method=None):
if hasattr(self, '_capturing'):
raise ValueError("cannot resume, already capturing with %r" %
(self._capturing,))
if method is None:
method = self._defaultmethod
cap = self._method2capture.get(method)
self._capturing = method
if cap is None:
self._method2capture[method] = cap = self._getcapture(method)
cap.startall()
else:
cap.resume()
def suspendcapture(self, item=None):
def suspendcapture(self, in_=False):
self.deactivate_funcargs()
if hasattr(self, '_capturing'):
method = self._capturing
cap = self._method2capture.get(method)
if cap is not None:
outerr = cap.suspend()
del self._capturing
if item:
outerr = (item.outerr[0] + outerr[0],
item.outerr[1] + outerr[1])
cap = getattr(self, "_capturing", None)
if cap is not None:
outerr = cap.readouterr()
cap.suspend_capturing(in_=in_)
return outerr
if hasattr(item, 'outerr'):
return item.outerr
return "", ""
def activate_funcargs(self, pyfuncitem):
funcargs = getattr(pyfuncitem, "funcargs", None)
if funcargs is not None:
for name, capfuncarg in funcargs.items():
if name in ('capsys', 'capfd'):
assert not hasattr(self, '_capturing_funcarg')
self._capturing_funcarg = capfuncarg
capfuncarg._start()
capfuncarg = pyfuncitem.__dict__.pop("_capfuncarg", None)
if capfuncarg is not None:
capfuncarg._start()
self._capfuncarg = capfuncarg
def deactivate_funcargs(self):
capturing_funcarg = getattr(self, '_capturing_funcarg', None)
if capturing_funcarg:
outerr = capturing_funcarg._finalize()
del self._capturing_funcarg
return outerr
capfuncarg = self.__dict__.pop("_capfuncarg", None)
if capfuncarg is not None:
capfuncarg.close()
@pytest.mark.tryfirst
def pytest_make_collect_report(self, __multicall__, collector):
method = self._getmethod(collector.config, collector.fspath)
try:
self.resumecapture(method)
except ValueError:
return # recursive collect, XXX refactor capturing
# to allow for more lightweight recursive capturing
if not isinstance(collector, pytest.File):
return
self.resumecapture()
try:
rep = __multicall__.execute()
finally:
outerr = self.suspendcapture()
addouterr(rep, outerr)
out, err = self.suspendcapture()
if out:
rep.sections.append(("Captured stdout", out))
if err:
rep.sections.append(("Captured stderr", err))
return rep
@pytest.mark.tryfirst
@pytest.mark.hookwrapper
def pytest_runtest_setup(self, item):
self.resumecapture_item(item)
self.resumecapture()
yield
self.suspendcapture_item(item, "setup")
@pytest.mark.tryfirst
@pytest.mark.hookwrapper
def pytest_runtest_call(self, item):
self.resumecapture_item(item)
self.resumecapture()
self.activate_funcargs(item)
yield
#self.deactivate_funcargs() called from suspendcapture()
self.suspendcapture_item(item, "call")
@pytest.mark.tryfirst
@pytest.mark.hookwrapper
def pytest_runtest_teardown(self, item):
self.resumecapture_item(item)
def pytest_keyboard_interrupt(self, excinfo):
if hasattr(self, '_capturing'):
self.suspendcapture()
self.resumecapture()
yield
self.suspendcapture_item(item, "teardown")
@pytest.mark.tryfirst
def pytest_runtest_makereport(self, __multicall__, item, call):
funcarg_outerr = self.deactivate_funcargs()
rep = __multicall__.execute()
outerr = self.suspendcapture(item)
if funcarg_outerr is not None:
outerr = (outerr[0] + funcarg_outerr[0],
outerr[1] + funcarg_outerr[1])
addouterr(rep, outerr)
if not rep.passed or rep.when == "teardown":
outerr = ('', '')
item.outerr = outerr
return rep
def pytest_keyboard_interrupt(self, excinfo):
self.reset_capturings()
@pytest.mark.tryfirst
def pytest_internalerror(self, excinfo):
self.reset_capturings()
def suspendcapture_item(self, item, when):
out, err = self.suspendcapture()
item.add_report_section(when, "out", out)
item.add_report_section(when, "err", err)
error_capsysfderror = "cannot use capsys and capfd at the same time"
def pytest_funcarg__capsys(request):
@pytest.fixture
def capsys(request):
"""enables capturing of writes to sys.stdout/sys.stderr and makes
captured output available via ``capsys.readouterr()`` method calls
which return a ``(out, err)`` tuple.
"""
if "capfd" in request._funcargs:
raise request.raiseerror(error_capsysfderror)
return CaptureFixture(py.io.StdCapture)
request.node._capfuncarg = c = CaptureFixture(SysCapture)
return c
def pytest_funcarg__capfd(request):
@pytest.fixture
def capfd(request):
"""enables capturing of writes to file descriptors 1 and 2 and makes
captured output available via ``capsys.readouterr()`` method calls
captured output available via ``capfd.readouterr()`` method calls
which return a ``(out, err)`` tuple.
"""
if "capsys" in request._funcargs:
request.raiseerror(error_capsysfderror)
if not hasattr(os, 'dup'):
pytest.skip("capfd funcarg needs os.dup")
return CaptureFixture(py.io.StdCaptureFD)
request.node._capfuncarg = c = CaptureFixture(FDCapture)
return c
class CaptureFixture:
def __init__(self, captureclass):
self.capture = captureclass(now=False)
self.captureclass = captureclass
def _start(self):
self.capture.startall()
self._capture = MultiCapture(out=True, err=True, in_=False,
Capture=self.captureclass)
self._capture.start_capturing()
def _finalize(self):
if hasattr(self, 'capture'):
outerr = self._outerr = self.capture.reset()
del self.capture
return outerr
def close(self):
cap = self.__dict__.pop("_capture", None)
if cap is not None:
self._outerr = cap.pop_outerr_to_orig()
cap.stop_capturing()
def readouterr(self):
try:
return self.capture.readouterr()
return self._capture.readouterr()
except AttributeError:
return self._outerr
def safe_text_dupfile(f, mode, default_encoding="UTF8"):
""" return a open text file object that's a duplicate of f on the
FD-level if possible.
"""
encoding = getattr(f, "encoding", None)
try:
fd = f.fileno()
except Exception:
if "b" not in getattr(f, "mode", "") and hasattr(f, "encoding"):
# we seem to have a text stream, let's just use it
return f
else:
newfd = os.dup(fd)
if "b" not in mode:
mode += "b"
f = os.fdopen(newfd, mode, 0) # no buffering
return EncodedFile(f, encoding or default_encoding)
class EncodedFile(object):
errors = "strict" # possibly needed by py3 code (issue555)
def __init__(self, buffer, encoding):
self.buffer = buffer
self.encoding = encoding
def write(self, obj):
if isinstance(obj, unicode):
obj = obj.encode(self.encoding, "replace")
self.buffer.write(obj)
def writelines(self, linelist):
data = ''.join(linelist)
self.write(data)
def __getattr__(self, name):
return getattr(self.buffer, name)
class MultiCapture(object):
out = err = in_ = None
def __init__(self, out=True, err=True, in_=True, Capture=None):
if in_:
self.in_ = Capture(0)
if out:
self.out = Capture(1)
if err:
self.err = Capture(2)
def start_capturing(self):
if self.in_:
self.in_.start()
if self.out:
self.out.start()
if self.err:
self.err.start()
def pop_outerr_to_orig(self):
""" pop current snapshot out/err capture and flush to orig streams. """
out, err = self.readouterr()
if out:
self.out.writeorg(out)
if err:
self.err.writeorg(err)
return out, err
def suspend_capturing(self, in_=False):
if self.out:
self.out.suspend()
if self.err:
self.err.suspend()
if in_ and self.in_:
self.in_.suspend()
self._in_suspended = True
def resume_capturing(self):
if self.out:
self.out.resume()
if self.err:
self.err.resume()
if hasattr(self, "_in_suspended"):
self.in_.resume()
del self._in_suspended
def stop_capturing(self):
""" stop capturing and reset capturing streams """
if hasattr(self, '_reset'):
raise ValueError("was already stopped")
self._reset = True
if self.out:
self.out.done()
if self.err:
self.err.done()
if self.in_:
self.in_.done()
def readouterr(self):
""" return snapshot unicode value of stdout/stderr capturings. """
return (self.out.snap() if self.out is not None else "",
self.err.snap() if self.err is not None else "")
class NoCapture:
__init__ = start = done = suspend = resume = lambda *args: None
class FDCapture:
""" Capture IO to/from a given os-level filedescriptor. """
def __init__(self, targetfd, tmpfile=None):
self.targetfd = targetfd
try:
self.targetfd_save = os.dup(self.targetfd)
except OSError:
self.start = lambda: None
self.done = lambda: None
else:
if targetfd == 0:
assert not tmpfile, "cannot set tmpfile with stdin"
tmpfile = open(os.devnull, "r")
self.syscapture = SysCapture(targetfd)
else:
if tmpfile is None:
f = TemporaryFile()
with f:
tmpfile = safe_text_dupfile(f, mode="wb+")
if targetfd in patchsysdict:
self.syscapture = SysCapture(targetfd, tmpfile)
else:
self.syscapture = NoCapture()
self.tmpfile = tmpfile
self.tmpfile_fd = tmpfile.fileno()
def __repr__(self):
return "<FDCapture %s oldfd=%s>" % (self.targetfd, self.targetfd_save)
def start(self):
""" Start capturing on targetfd using memorized tmpfile. """
try:
os.fstat(self.targetfd_save)
except (AttributeError, OSError):
raise ValueError("saved filedescriptor not valid anymore")
os.dup2(self.tmpfile_fd, self.targetfd)
self.syscapture.start()
def snap(self):
f = self.tmpfile
f.seek(0)
res = f.read()
if res:
enc = getattr(f, "encoding", None)
if enc and isinstance(res, bytes):
res = py.builtin._totext(res, enc, "replace")
f.truncate(0)
f.seek(0)
return res
return ''
def done(self):
""" stop capturing, restore streams, return original capture file,
seeked to position zero. """
targetfd_save = self.__dict__.pop("targetfd_save")
os.dup2(targetfd_save, self.targetfd)
os.close(targetfd_save)
self.syscapture.done()
self.tmpfile.close()
def suspend(self):
self.syscapture.suspend()
os.dup2(self.targetfd_save, self.targetfd)
def resume(self):
self.syscapture.resume()
os.dup2(self.tmpfile_fd, self.targetfd)
def writeorg(self, data):
""" write to original file descriptor. """
if py.builtin._istext(data):
data = data.encode("utf8") # XXX use encoding of original stream
os.write(self.targetfd_save, data)
class SysCapture:
def __init__(self, fd, tmpfile=None):
name = patchsysdict[fd]
self._old = getattr(sys, name)
self.name = name
if tmpfile is None:
if name == "stdin":
tmpfile = DontReadFromInput()
else:
tmpfile = TextIO()
self.tmpfile = tmpfile
def start(self):
setattr(sys, self.name, self.tmpfile)
def snap(self):
f = self.tmpfile
res = f.getvalue()
f.truncate(0)
f.seek(0)
return res
def done(self):
setattr(sys, self.name, self._old)
del self._old
self.tmpfile.close()
def suspend(self):
setattr(sys, self.name, self._old)
def resume(self):
setattr(sys, self.name, self.tmpfile)
def writeorg(self, data):
self._old.write(data)
self._old.flush()
class DontReadFromInput:
"""Temporary stub class. Ideally when stdin is accessed, the
capturing should be turned off, with possibly all data captured
so far sent to the screen. This should be configurable, though,
because in automated test runs it is better to crash than
hang indefinitely.
"""
def read(self, *args):
raise IOError("reading from stdin while output is captured")
readline = read
readlines = read
__iter__ = read
def fileno(self):
raise ValueError("redirected Stdin is pseudofile, has no fileno()")
def isatty(self):
return False
def close(self):
self._finalize()
pass

View File

@@ -1,11 +1,24 @@
""" command line options, ini-file and conftest.py processing. """
import argparse
import shlex
import traceback
import types
import warnings
import py
# DON't import pytest here because it causes import cycle troubles
import sys, os
from _pytest import hookspec # the extension point definitions
from _pytest.core import PluginManager
# pytest startup
#
class ConftestImportFailure(Exception):
def __init__(self, path, excinfo):
Exception.__init__(self, path, excinfo)
self.path = path
self.excinfo = excinfo
def main(args=None, plugins=None):
""" return exit code, after performing an in-process test run.
@@ -15,14 +28,23 @@ def main(args=None, plugins=None):
:arg plugins: list of plugin objects to be auto-registered during
initialization.
"""
config = _prepareconfig(args, plugins)
return config.hook.pytest_cmdline_main(config=config)
try:
config = _prepareconfig(args, plugins)
except ConftestImportFailure:
e = sys.exc_info()[1]
tw = py.io.TerminalWriter(sys.stderr)
for line in traceback.format_exception(*e.excinfo):
tw.line(line.rstrip(), red=True)
tw.line("ERROR: could not load %s\n" % (e.path), red=True)
return 4
else:
return config.hook.pytest_cmdline_main(config=config)
class cmdline: # compatibility namespace
main = staticmethod(main)
class UsageError(Exception):
""" error in py.test usage or invocation"""
""" error in pytest usage or invocation"""
_preinit = []
@@ -53,13 +75,17 @@ def _prepareconfig(args=None, plugins=None):
elif not isinstance(args, (tuple, list)):
if not isinstance(args, str):
raise ValueError("not a string or argument list: %r" % (args,))
args = py.std.shlex.split(args)
args = shlex.split(args)
pluginmanager = get_plugin_manager()
if plugins:
for plugin in plugins:
pluginmanager.register(plugin)
return pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args)
try:
if plugins:
for plugin in plugins:
pluginmanager.register(plugin)
return pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args)
except Exception:
pluginmanager.ensure_shutdown()
raise
class PytestPluginManager(PluginManager):
def __init__(self, hookspecs=[hookspec]):
@@ -81,6 +107,8 @@ class PytestPluginManager(PluginManager):
config.addinivalue_line("markers",
"trylast: mark a hook implementation function such that the "
"plugin machinery will try to call it last/as late as possible.")
for warning in self._warnings:
config.warn(code="I1", message=warning)
class Parser:
@@ -93,7 +121,6 @@ class Parser:
self._usage = usage
self._inidict = {}
self._ininames = []
self.hints = []
def processoption(self, option):
if self._processopt:
@@ -158,8 +185,7 @@ class Parser:
a = option.attrs()
arggroup.add_argument(*n, **a)
# bash like autocompletion for dirs (appending '/')
optparser.add_argument(FILE_OR_DIR, nargs='*'
).completer=filescompleter
optparser.add_argument(FILE_OR_DIR, nargs='*').completer=filescompleter
return optparser
def parse_setoption(self, args, option):
@@ -206,7 +232,7 @@ class ArgumentError(Exception):
class Argument:
"""class that mimics the necessary behaviour of py.std.optparse.Option """
"""class that mimics the necessary behaviour of optparse.Option """
_typ_map = {
'int': int,
'string': str,
@@ -224,8 +250,8 @@ class Argument:
try:
help = attrs['help']
if '%default' in help:
py.std.warnings.warn(
'py.test now uses argparse. "%default" should be'
warnings.warn(
'pytest now uses argparse. "%default" should be'
' changed to "%(default)s" ',
FutureWarning,
stacklevel=3)
@@ -240,7 +266,7 @@ class Argument:
if isinstance(typ, py.builtin._basestring):
if typ == 'choice':
if self.TYPE_WARN:
py.std.warnings.warn(
warnings.warn(
'type argument to addoption() is a string %r.'
' For parsearg this is optional and when supplied '
' should be a type.'
@@ -252,7 +278,7 @@ class Argument:
attrs['type'] = type(attrs['choices'][0])
else:
if self.TYPE_WARN:
py.std.warnings.warn(
warnings.warn(
'type argument to addoption() is a string %r.'
' For parsearg this should be a type.'
' (options: %s)' % (typ, names),
@@ -372,32 +398,24 @@ class OptionGroup:
self.options.append(option)
class MyOptionParser(py.std.argparse.ArgumentParser):
class MyOptionParser(argparse.ArgumentParser):
def __init__(self, parser):
self._parser = parser
py.std.argparse.ArgumentParser.__init__(self, usage=parser._usage,
argparse.ArgumentParser.__init__(self, usage=parser._usage,
add_help=False, formatter_class=DropShorterLongHelpFormatter)
def format_epilog(self, formatter):
hints = self._parser.hints
if hints:
s = "\n".join(["hint: " + x for x in hints]) + "\n"
s = "\n" + s + "\n"
return s
return ""
def parse_args(self, args=None, namespace=None):
"""allow splitting of positional arguments"""
args, argv = self.parse_known_args(args, namespace)
if argv:
for arg in argv:
if arg and arg[0] == '-':
msg = py.std.argparse._('unrecognized arguments: %s')
msg = argparse._('unrecognized arguments: %s')
self.error(msg % ' '.join(argv))
getattr(args, FILE_OR_DIR).extend(argv)
return args
class DropShorterLongHelpFormatter(py.std.argparse.HelpFormatter):
class DropShorterLongHelpFormatter(argparse.HelpFormatter):
"""shorten help for long options that differ only in extra hyphens
- collapse **long** options that are the same except for extra hyphens
@@ -407,7 +425,7 @@ class DropShorterLongHelpFormatter(py.std.argparse.HelpFormatter):
- cache result on action object as this is called at least 2 times
"""
def _format_action_invocation(self, action):
orgstr = py.std.argparse.HelpFormatter._format_action_invocation(self, action)
orgstr = argparse.HelpFormatter._format_action_invocation(self, action)
if orgstr and orgstr[0] != '-': # only optional arguments
return orgstr
res = getattr(action, '_formatted_action_invocation', None)
@@ -441,47 +459,41 @@ class DropShorterLongHelpFormatter(py.std.argparse.HelpFormatter):
if len(option) == 2 or option[2] == ' ':
return_list.append(option)
if option[2:] == short_long.get(option.replace('-', '')):
return_list.append(option)
return_list.append(option.replace(' ', '='))
action._formatted_action_invocation = ', '.join(return_list)
return action._formatted_action_invocation
class Conftest(object):
""" the single place for accessing values and interacting
towards conftest modules from py.test objects.
towards conftest modules from pytest objects.
"""
def __init__(self, onimport=None, confcutdir=None):
def __init__(self, onimport=None):
self._path2confmods = {}
self._onimport = onimport
self._conftestpath2mod = {}
self._confcutdir = confcutdir
self._confcutdir = None
def setinitial(self, args):
""" try to find a first anchor path for looking up global values
from conftests. This function is usually called _before_
argument parsing. conftest files may add command line options
and we thus have no completely safe way of determining
which parts of the arguments are actually related to options
and which are file system paths. We just try here to get
bootstrapped ...
def setinitial(self, namespace):
""" load initial conftest files given a preparsed "namespace".
As conftest files may add their own command line options
which have arguments ('--my-opt somepath') we might get some
false positives. All builtin and 3rd party plugins will have
been loaded, however, so common options will not confuse our logic
here.
"""
current = py.path.local()
opt = '--confcutdir'
for i in range(len(args)):
opt1 = str(args[i])
if opt1.startswith(opt):
if opt1 == opt:
if len(args) > i:
p = current.join(args[i+1], abs=True)
elif opt1.startswith(opt + "="):
p = current.join(opt1[len(opt)+1:], abs=1)
self._confcutdir = p
break
self._confcutdir = current.join(namespace.confcutdir, abs=True) \
if namespace.confcutdir else None
testpaths = namespace.file_or_dir
foundanchor = False
for arg in args:
if hasattr(arg, 'startswith') and arg.startswith("--"):
continue
anchor = current.join(arg, abs=1)
for path in testpaths:
path = str(path)
# remove node-id syntax
i = path.find("::")
if i != -1:
path = path[:i]
anchor = current.join(path, abs=1)
if exists(anchor): # we found some file object
self._try_load_conftest(anchor)
foundanchor = True
@@ -489,7 +501,7 @@ class Conftest(object):
self._try_load_conftest(current)
def _try_load_conftest(self, anchor):
self._path2confmods[None] = self.getconftestmodules(anchor)
self.getconftestmodules(anchor)
# let's also consider test* subdirs
if anchor.check(dir=1):
for x in anchor.listdir("test*"):
@@ -498,28 +510,22 @@ class Conftest(object):
def getconftestmodules(self, path):
try:
clist = self._path2confmods[path]
return self._path2confmods[path]
except KeyError:
if path is None:
raise ValueError("missing default conftest.")
clist = []
for parent in path.parts():
if self._confcutdir and self._confcutdir.relto(parent):
continue
conftestpath = parent.join("conftest.py")
if conftestpath.check(file=1):
clist.append(self.importconftest(conftestpath))
mod = self.importconftest(conftestpath)
clist.append(mod)
self._path2confmods[path] = clist
return clist
return clist
def rget(self, name, path=None):
mod, value = self.rget_with_confmod(name, path)
return value
def rget_with_confmod(self, name, path=None):
def rget_with_confmod(self, name, path):
modules = self.getconftestmodules(path)
modules.reverse()
for mod in modules:
for mod in reversed(modules):
try:
return mod, getattr(mod, name)
except AttributeError:
@@ -527,27 +533,27 @@ class Conftest(object):
raise KeyError(name)
def importconftest(self, conftestpath):
assert conftestpath.check(), conftestpath
try:
return self._conftestpath2mod[conftestpath]
except KeyError:
pkgpath = conftestpath.pypkgpath()
if pkgpath is None:
_ensure_removed_sysmodule(conftestpath.purebasename)
self._conftestpath2mod[conftestpath] = mod = conftestpath.pyimport()
try:
mod = conftestpath.pyimport()
except Exception:
raise ConftestImportFailure(conftestpath, sys.exc_info())
self._conftestpath2mod[conftestpath] = mod
dirpath = conftestpath.dirpath()
if dirpath in self._path2confmods:
for path, mods in self._path2confmods.items():
if path and path.relto(dirpath) or path == dirpath:
assert mod not in mods
mods.append(mod)
self._postimport(mod)
if self._onimport:
self._onimport(mod)
return mod
def _postimport(self, mod):
if self._onimport:
self._onimport(mod)
return mod
def _ensure_removed_sysmodule(modname):
try:
@@ -562,6 +568,11 @@ class CmdOptions(object):
def __repr__(self):
return "<CmdOptions %r>" %(self.__dict__,)
class Notset:
def __repr__(self):
return "<NOTSET>"
notset = Notset()
FILE_OR_DIR = 'file_or_dir'
class Config(object):
""" access to configuration values, pluginmanager and plugin hooks. """
@@ -612,6 +623,14 @@ class Config(object):
self.hook.pytest_unconfigure(config=self)
self.pluginmanager.ensure_shutdown()
def warn(self, code, message):
""" generate a warning for this test session. """
self.hook.pytest_logwarning(code=code, message=message,
fslocation=None, nodeid=None)
def get_terminal_writer(self):
return self.pluginmanager.getplugin("terminalreporter")._tw
def pytest_cmdline_parse(self, pluginmanager, args):
assert self == pluginmanager.config, (self, pluginmanager.config)
self.parse(args)
@@ -669,12 +688,20 @@ class Config(object):
plugins += self._conftest.getconftestmodules(fspath)
return plugins
def pytest_load_initial_conftests(self, parser, args):
self._conftest.setinitial(args)
def pytest_load_initial_conftests(self, early_config):
self._conftest.setinitial(early_config.known_args_namespace)
pytest_load_initial_conftests.trylast = True
def _initini(self, args):
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
parsed_args = self._parser.parse_known_args(args)
if parsed_args.inifilename:
iniconfig = py.iniconfig.IniConfig(parsed_args.inifilename)
if 'pytest' in iniconfig.sections:
self.inicfg = iniconfig['pytest']
else:
self.inicfg = {}
else:
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
self._parser.addini('addopts', 'extra command line options', 'args')
self._parser.addini('minversion', 'minimally required pytest version')
@@ -686,8 +713,19 @@ class Config(object):
self.pluginmanager.consider_preparse(args)
self.pluginmanager.consider_setuptools_entrypoints()
self.pluginmanager.consider_env()
self.hook.pytest_load_initial_conftests(early_config=self,
args=args, parser=self._parser)
self.known_args_namespace = ns = self._parser.parse_known_args(args)
try:
self.hook.pytest_load_initial_conftests(early_config=self,
args=args, parser=self._parser)
except ConftestImportFailure:
e = sys.exc_info()[1]
if ns.help or ns.version:
# we don't want to prevent --help/--version to work
# so just let is pass and print a warning at the end
self.pluginmanager._warnings.append(
"could not load initial conftests (%s)\n" % e.path)
else:
raise
def _checkversion(self):
import pytest
@@ -703,17 +741,15 @@ class Config(object):
def parse(self, args):
# parse given cmdline arguments into this config object.
# Note that this can only be called once per testing process.
assert not hasattr(self, 'args'), (
"can only parse cmdline args at most once per Config object")
self._origargs = args
self._preparse(args)
# XXX deprecated hook:
self.hook.pytest_cmdline_preparse(config=self, args=args)
self._parser.hints.extend(self.pluginmanager._hints)
args = self._parser.parse_setoption(args, self.option)
if not args:
args.append(py.std.os.getcwd())
args.append(os.getcwd())
self.args = args
def addinivalue_line(self, name, line):
@@ -751,18 +787,18 @@ class Config(object):
if type == "pathlist":
dp = py.path.local(self.inicfg.config.path).dirpath()
l = []
for relpath in py.std.shlex.split(value):
for relpath in shlex.split(value):
l.append(dp.join(relpath, abs=True))
return l
elif type == "args":
return py.std.shlex.split(value)
return shlex.split(value)
elif type == "linelist":
return [t for t in map(lambda x: x.strip(), value.split("\n")) if t]
else:
assert type is None
return value
def _getconftest_pathlist(self, name, path=None):
def _getconftest_pathlist(self, name, path):
try:
mod, relroots = self._conftest.rget_with_confmod(name, path)
except KeyError:
@@ -776,47 +812,36 @@ class Config(object):
l.append(relroot)
return l
def _getconftest(self, name, path=None, check=False):
if check:
self._checkconftest(name)
return self._conftest.rget(name, path)
def getoption(self, name):
def getoption(self, name, default=notset, skip=False):
""" return command line option value.
:arg name: name of the option. You may also specify
the literal ``--OPT`` option instead of the "dest" option name.
:arg default: default value if no option of that name exists.
:arg skip: if True raise pytest.skip if option does not exists
or has a None value.
"""
name = self._opt2dest.get(name, name)
try:
return getattr(self.option, name)
val = getattr(self.option, name)
if val is None and skip:
raise AttributeError(name)
return val
except AttributeError:
if default is not notset:
return default
if skip:
import pytest
pytest.skip("no %r option found" %(name,))
raise ValueError("no option named %r" % (name,))
def getvalue(self, name, path=None):
""" return command line option value.
:arg name: name of the command line option
(deprecated) if we can't find the option also lookup
the name in a matching conftest file.
"""
try:
return getattr(self.option, name)
except AttributeError:
return self._getconftest(name, path, check=False)
""" (deprecated, use getoption()) """
return self.getoption(name)
def getvalueorskip(self, name, path=None):
""" (deprecated) return getvalue(name) or call
py.test.skip if no value exists. """
__tracebackhide__ = True
try:
val = self.getvalue(name, path)
if val is None:
raise KeyError(name)
return val
except KeyError:
py.test.skip("no %r value found" %(name,))
""" (deprecated, use getoption(skip=True)) """
return self.getoption(name, skip=True)
def exists(path, ignore=EnvironmentError):
try:
@@ -847,7 +872,7 @@ def setns(obj, dic):
mod = getattr(obj, name, None)
if mod is None:
modname = "pytest.%s" % name
mod = py.std.types.ModuleType(modname)
mod = types.ModuleType(modname)
sys.modules[modname] = mod
mod.__all__ = []
setattr(obj, name, mod)

View File

@@ -1,9 +1,11 @@
"""
pytest PluginManager, basic initialization and tracing.
"""
import os
import sys
import inspect
import py
# don't import pytest to avoid circular imports
assert py.__version__.split(".")[:2] >= ['1', '4'], ("installation problem: "
"%s is too old, remove or upgrade 'py'" % (py.__version__))
@@ -70,7 +72,7 @@ class PluginManager(object):
self._name2plugin = {}
self._listattrcache = {}
self._plugins = []
self._hints = []
self._warnings = []
self.trace = TagTracer().get("pluginmanage")
self._plugin_distinfo = []
self._shutdown = []
@@ -136,7 +138,8 @@ class PluginManager(object):
def skipifmissing(self, name):
if not self.hasplugin(name):
py.test.skip("plugin %r is missing" % name)
import pytest
pytest.skip("plugin %r is missing" % name)
def hasplugin(self, name):
return bool(self.getplugin(name))
@@ -152,7 +155,7 @@ class PluginManager(object):
# API for bootstrapping
#
def _envlist(self, varname):
val = py.std.os.environ.get(varname, None)
val = os.environ.get(varname, None)
if val is not None:
return val.split(',')
return ()
@@ -219,12 +222,11 @@ class PluginManager(object):
return self.import_plugin(modname[7:])
raise
except:
e = py.std.sys.exc_info()[1]
if not hasattr(py.test, 'skip'):
e = sys.exc_info()[1]
import pytest
if not hasattr(pytest, 'skip') or not isinstance(e, pytest.skip.Exception):
raise
elif not isinstance(e, py.test.skip.Exception):
raise
self._hints.append("skipped plugin %r: %s" %((modname, e.msg)))
self._warnings.append("skipped plugin %r: %s" %((modname, e.msg)))
else:
self.register(mod, modname)
self.consider_module(mod)
@@ -239,18 +241,22 @@ class PluginManager(object):
pass
l = []
last = []
wrappers = []
for plugin in plugins:
try:
meth = getattr(plugin, attrname)
if hasattr(meth, 'tryfirst'):
last.append(meth)
elif hasattr(meth, 'trylast'):
l.insert(0, meth)
else:
l.append(meth)
except AttributeError:
continue
if hasattr(meth, 'hookwrapper'):
wrappers.append(meth)
elif hasattr(meth, 'tryfirst'):
last.append(meth)
elif hasattr(meth, 'trylast'):
l.insert(0, meth)
else:
l.append(meth)
l.extend(last)
l.extend(wrappers)
self._listattrcache[key] = list(l)
return l
@@ -271,6 +277,14 @@ def importplugin(importspec):
class MultiCall:
""" execute a call into multiple python functions/methods. """
class WrongHookWrapper(Exception):
""" a hook wrapper does not behave correctly. """
def __init__(self, func, message):
Exception.__init__(self, func, message)
self.func = func
self.message = message
def __init__(self, methods, kwargs, firstresult=False):
self.methods = list(methods)
self.kwargs = kwargs
@@ -282,16 +296,39 @@ class MultiCall:
return "<MultiCall %s, kwargs=%r>" %(status, self.kwargs)
def execute(self):
while self.methods:
method = self.methods.pop()
kwargs = self.getkwargs(method)
res = method(**kwargs)
if res is not None:
self.results.append(res)
if self.firstresult:
return res
if not self.firstresult:
return self.results
next_finalizers = []
try:
while self.methods:
method = self.methods.pop()
kwargs = self.getkwargs(method)
if hasattr(method, "hookwrapper"):
it = method(**kwargs)
next = getattr(it, "next", None)
if next is None:
next = getattr(it, "__next__", None)
if next is None:
raise self.WrongHookWrapper(method,
"wrapper does not contain a yield")
res = next()
next_finalizers.append((method, next))
else:
res = method(**kwargs)
if res is not None:
self.results.append(res)
if self.firstresult:
return res
if not self.firstresult:
return self.results
finally:
for method, fin in reversed(next_finalizers):
try:
fin()
except StopIteration:
pass
else:
raise self.WrongHookWrapper(method,
"wrapper contain more than one yield")
def getkwargs(self, method):
kwargs = {}

View File

@@ -1,5 +1,6 @@
""" discover and run doctests in modules and test files."""
from __future__ import absolute_import
import traceback
import pytest, py
from _pytest.python import FixtureRequest, FuncFixtureInfo
from py._code.code import TerminalRepr, ReprFileLocation
@@ -43,7 +44,7 @@ class DoctestItem(pytest.Item):
self.runner.run(self.dtest)
def repr_failure(self, excinfo):
doctest = py.std.doctest
import doctest
if excinfo.errisinstance((doctest.DocTestFailure,
doctest.UnexpectedException)):
doctestfailure = excinfo.value
@@ -56,8 +57,8 @@ class DoctestItem(pytest.Item):
lineno = test.lineno + example.lineno + 1
message = excinfo.type.__name__
reprlocation = ReprFileLocation(filename, lineno, message)
checker = py.std.doctest.OutputChecker()
REPORT_UDIFF = py.std.doctest.REPORT_UDIFF
checker = doctest.OutputChecker()
REPORT_UDIFF = doctest.REPORT_UDIFF
filelines = py.path.local(filename).readlines(cr=0)
lines = []
if lineno is not None:
@@ -78,7 +79,7 @@ class DoctestItem(pytest.Item):
inner_excinfo = py.code.ExceptionInfo(excinfo.value.exc_info)
lines += ["UNEXPECTED EXCEPTION: %s" %
repr(inner_excinfo.value)]
lines += py.std.traceback.format_exception(*excinfo.value.exc_info)
lines += traceback.format_exception(*excinfo.value.exc_info)
return ReprFailDoctest(reprlocation, lines)
else:
return super(DoctestItem, self).repr_failure(excinfo)
@@ -88,7 +89,7 @@ class DoctestItem(pytest.Item):
class DoctestTextfile(DoctestItem, pytest.File):
def runtest(self):
doctest = py.std.doctest
import doctest
# satisfy `FixtureRequest` constructor...
self.funcargs = {}
fm = self.session._fixturemanager
@@ -106,7 +107,7 @@ class DoctestTextfile(DoctestItem, pytest.File):
class DoctestModule(pytest.File):
def collect(self):
doctest = py.std.doctest
import doctest
if self.fspath.basename == "conftest.py":
module = self.config._conftest.importconftest(self.fspath)
else:

View File

@@ -1,9 +1,16 @@
""" generate a single-file self-contained version of py.test """
import py
""" generate a single-file self-contained version of pytest """
import os
import sys
import pkgutil
import py
import _pytest
def find_toplevel(name):
for syspath in py.std.sys.path:
for syspath in sys.path:
base = py.path.local(syspath)
lib = base/name
if lib.check(dir=1):
@@ -29,9 +36,10 @@ def pkg_to_mapping(name):
return name2src
def compress_mapping(mapping):
data = py.std.pickle.dumps(mapping, 2)
data = py.std.zlib.compress(data, 9)
data = py.std.base64.encodestring(data)
import base64, pickle, zlib
data = pickle.dumps(mapping, 2)
data = zlib.compress(data, 9)
data = base64.encodestring(data)
data = data.decode('ascii')
return data
@@ -55,7 +63,7 @@ def pytest_addoption(parser):
group = parser.getgroup("debugconfig")
group.addoption("--genscript", action="store", default=None,
dest="genscript", metavar="path",
help="create standalone py.test script at given target path.")
help="create standalone pytest script at given target path.")
def pytest_cmdline_main(config):
genscript = config.getvalue("genscript")
@@ -64,13 +72,13 @@ def pytest_cmdline_main(config):
deps = ['py', '_pytest', 'pytest']
if sys.version_info < (2,7):
deps.append("argparse")
tw.line("generated script will run on python2.5-python3.3++")
tw.line("generated script will run on python2.6-python3.3++")
else:
tw.line("WARNING: generated script will not run on python2.6 "
"or below due to 'argparse' dependency. Use python2.6 "
"to generate a python2.5/6 compatible script", red=True)
"due to 'argparse' dependency. Use python2.6 "
"to generate a python2.6 compatible script", red=True)
script = generate_script(
'import py; raise SystemExit(py.test.cmdline.main())',
'import pytest; raise SystemExit(pytest.cmdline.main())',
deps,
)
genscript = py.path.local(genscript)
@@ -78,3 +86,42 @@ def pytest_cmdline_main(config):
tw.line("generated pytest standalone script: %s" % genscript,
bold=True)
return 0
def pytest_namespace():
return {'freeze_includes': freeze_includes}
def freeze_includes():
"""
Returns a list of module names used by py.test that should be
included by cx_freeze.
"""
result = list(_iter_all_modules(py))
result += list(_iter_all_modules(_pytest))
return result
def _iter_all_modules(package, prefix=''):
"""
Iterates over the names of all modules that can be found in the given
package, recursively.
Example:
_iter_all_modules(_pytest) ->
['_pytest.assertion.newinterpret',
'_pytest.capture',
'_pytest.core',
...
]
"""
if type(package) is not str:
path, prefix = package.__path__[0], package.__name__ + '.'
else:
path = package
for _, name, is_package in pkgutil.iter_modules([path]):
if is_package:
for m in _iter_all_modules(os.path.join(path, name), prefix=name + '.'):
yield prefix + m
else:
yield prefix + name

View File

@@ -12,7 +12,9 @@ def pytest_addoption(parser):
help="show help message and configuration info")
group._addoption('-p', action="append", dest="plugins", default = [],
metavar="name",
help="early-load given plugin (multi-allowed).")
help="early-load given plugin (multi-allowed). "
"To avoid loading of plugins, use the `no:` prefix, e.g. "
"`no:doctest`.")
group.addoption('--traceconfig', '--trace-config',
action="store_true", default=False,
help="trace considerations of conftest.py files."),
@@ -46,7 +48,7 @@ def pytest_unconfigure(config):
def pytest_cmdline_main(config):
if config.option.version:
p = py.path.local(pytest.__file__)
sys.stderr.write("This is py.test version %s, imported from %s\n" %
sys.stderr.write("This is pytest version %s, imported from %s\n" %
(pytest.__version__, p))
plugininfo = getpluginversioninfo(config)
if plugininfo:
@@ -62,7 +64,6 @@ def pytest_cmdline_main(config):
def showhelp(config):
tw = py.io.TerminalWriter()
tw.write(config._parser.optparser.format_help())
tw.write(config._parser.optparser.format_epilog(None))
tw.line()
tw.line()
#tw.sep( "=", "config file settings")
@@ -82,16 +83,12 @@ def showhelp(config):
#tw.sep("=")
tw.line("to see available markers type: py.test --markers")
tw.line("to see available fixtures type: py.test --fixtures")
tw.line("(shown according to specified file_or_dir or current dir "
"if not specified)")
for warning in config.pluginmanager._warnings:
tw.line("warning: %s" % (warning,), red=True)
return
tw.line("conftest.py options:")
tw.line()
conftestitems = sorted(config._parser._conftestdict.items())
for name, help in conftest_options + conftestitems:
line = " %-15s %s" %(name, help)
tw.line(line[:tw.fullwidth])
tw.line()
#tw.sep( "=")
conftest_options = [
('pytest_plugins', 'list of plugin names to load'),

View File

@@ -11,8 +11,8 @@ def pytest_addhooks(pluginmanager):
def pytest_namespace():
"""return dict of name->object to be made globally available in
the py.test/pytest namespace. This hook is called before command
line options are parsed.
the pytest namespace. This hook is called before command line options
are parsed.
"""
def pytest_cmdline_parse(pluginmanager, args):
@@ -53,8 +53,8 @@ def pytest_cmdline_main(config):
pytest_cmdline_main.firstresult = True
def pytest_load_initial_conftests(args, early_config, parser):
""" implements loading initial conftests.
"""
""" implements the loading of initial conftest files ahead
of command line option parsing. """
def pytest_configure(config):
""" called after command line options have been parsed
@@ -152,9 +152,9 @@ def pytest_runtest_protocol(item, nextitem):
:arg item: test item for which the runtest protocol is performed.
:arg nexitem: the scheduled-to-be-next test item (or None if this
is the end my friend). This argument is passed on to
:py:func:`pytest_runtest_teardown`.
:arg nextitem: the scheduled-to-be-next test item (or None if this
is the end my friend). This argument is passed on to
:py:func:`pytest_runtest_teardown`.
:return boolean: True if no further hook implementations should be invoked.
"""
@@ -172,10 +172,10 @@ def pytest_runtest_call(item):
def pytest_runtest_teardown(item, nextitem):
""" called after ``pytest_runtest_call``.
:arg nexitem: the scheduled-to-be-next test item (None if no further
test item is scheduled). This argument can be used to
perform exact teardowns, i.e. calling just enough finalizers
so that nextitem only needs to call setup-functions.
:arg nextitem: the scheduled-to-be-next test item (None if no further
test item is scheduled). This argument can be used to
perform exact teardowns, i.e. calling just enough finalizers
so that nextitem only needs to call setup-functions.
"""
def pytest_runtest_makereport(item, call):
@@ -227,6 +227,11 @@ pytest_report_teststatus.firstresult = True
def pytest_terminal_summary(terminalreporter):
""" add additional section in terminal summary reporting. """
def pytest_logwarning(message, code, nodeid, fslocation):
""" process a warning specified by a message, a code string,
a nodeid and fslocation (both of which may be None
if the warning is not tied to a partilar node/location)."""
# -------------------------------------------------------------------------
# doctest hooks
# -------------------------------------------------------------------------

View File

@@ -2,7 +2,6 @@
Based on initial code from Ross Lawley.
"""
import py
import os
import re
@@ -10,20 +9,13 @@ import sys
import time
# Python 2.X and 3.X compatibility
try:
unichr(65)
except NameError:
if sys.version_info[0] < 3:
from codecs import open
else:
unichr = chr
try:
unicode('A')
except NameError:
unicode = str
try:
long(1)
except NameError:
long = int
class Junit(py.xml.Namespace):
pass
@@ -108,12 +100,14 @@ class LogXML(object):
))
def _write_captured_output(self, report):
sec = dict(report.sections)
for name in ('out', 'err'):
content = sec.get("Captured std%s" % name)
if content:
tag = getattr(Junit, 'system-'+name)
self.append(tag(bin_xml_escape(content)))
for capname in ('out', 'err'):
allcontent = ""
for name, content in report.get_sections("Captured std%s" %
capname):
allcontent += content
if allcontent:
tag = getattr(Junit, 'system-'+capname)
self.append(tag(bin_xml_escape(allcontent)))
def append(self, obj):
self.tests[-1].append(obj)
@@ -161,7 +155,7 @@ class LogXML(object):
if skipreason.startswith("Skipped: "):
skipreason = bin_xml_escape(skipreason[9:])
self.append(
Junit.skipped("%s:%s: %s" % report.longrepr,
Junit.skipped("%s:%s: %s" % (filename, lineno, skipreason),
type="pytest.skip",
message=skipreason
))
@@ -204,11 +198,7 @@ class LogXML(object):
self.suite_start_time = time.time()
def pytest_sessionfinish(self):
if py.std.sys.version_info[0] < 3:
logfile = py.std.codecs.open(self.logfile, 'w', encoding='utf-8')
else:
logfile = open(self.logfile, 'w', encoding='utf-8')
logfile = open(self.logfile, 'w', encoding='utf-8')
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed

View File

@@ -1,4 +1,5 @@
""" core implementation of testing process: init, session, runtest loop. """
import re
import py
import pytest, _pytest
@@ -8,7 +9,7 @@ try:
except ImportError:
from UserDict import DictMixin as MappingMixin
from _pytest.runner import collect_one_node, Skipped
from _pytest.runner import collect_one_node
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
@@ -19,11 +20,11 @@ EXIT_INTERRUPTED = 2
EXIT_INTERNALERROR = 3
EXIT_USAGEERROR = 4
name_re = py.std.re.compile("^[a-zA-Z_]\w*$")
name_re = re.compile("^[a-zA-Z_]\w*$")
def pytest_addoption(parser):
parser.addini("norecursedirs", "directory patterns to avoid for recursion",
type="args", default=('.*', 'CVS', '_darcs', '{arch}'))
type="args", default=('.*', 'CVS', '_darcs', '{arch}', '*.egg'))
#parser.addini("dirpatterns",
# "patterns specifying possible locations of test files",
# type="linelist", default=["**/test_*.txt",
@@ -38,6 +39,8 @@ def pytest_addoption(parser):
help="exit after first num failures or errors.")
group._addoption('--strict', action="store_true",
help="run pytest in strict mode, warnings become errors.")
group._addoption("-c", metavar="file", type=str, dest="inifilename",
help="load configuration from `file` instead of trying to locate one of the implicit configuration files.")
group = parser.getgroup("collect", "collection")
group.addoption('--collectonly', '--collect-only', action="store_true",
@@ -63,7 +66,7 @@ def pytest_namespace():
return dict(collect=collect)
def pytest_configure(config):
py.test.config = config # compatibiltiy
pytest.config = config # compatibiltiy
if config.option.exitfirst:
config.option.maxfail = 1
@@ -80,8 +83,9 @@ def wrap_session(config, doit):
initstate = 2
doit(config, session)
except pytest.UsageError:
msg = sys.exc_info()[1].args[0]
sys.stderr.write("ERROR: %s\n" %(msg,))
args = sys.exc_info()[1].args
for msg in args:
sys.stderr.write("ERROR: %s\n" %(msg,))
session.exitstatus = EXIT_USAGEERROR
except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo()
@@ -97,6 +101,7 @@ def wrap_session(config, doit):
if session._testsfailed:
session.exitstatus = EXIT_TESTSFAILED
finally:
excinfo = None # Explicitly break reference cycle.
session.startdir.chdir()
if initstate >= 2:
config.hook.pytest_sessionfinish(
@@ -143,7 +148,7 @@ def pytest_ignore_collect(path, config):
p = path.dirpath()
ignore_paths = config._getconftest_pathlist("collect_ignore", path=p)
ignore_paths = ignore_paths or []
excludeopt = config.getvalue("ignore")
excludeopt = config.getoption("ignore")
if excludeopt:
ignore_paths.extend([py.path.local(x) for x in excludeopt])
return path in ignore_paths
@@ -232,6 +237,7 @@ class Node(object):
# used for storing artificial fixturedefs for direct parametrization
self._name2pseudofixturedef = {}
#self.extrainit()
@property
@@ -262,6 +268,20 @@ class Node(object):
return "<%s %r>" %(self.__class__.__name__,
getattr(self, 'name', None))
def warn(self, code, message):
""" generate a warning with the given code and message for this
item. """
assert isinstance(code, str)
fslocation = getattr(self, "location", None)
if fslocation is None:
fslocation = getattr(self, "fspath", None)
else:
fslocation = "%s:%s" % fslocation[:2]
self.ihook.pytest_logwarning(code=code, message=message,
nodeid=self.nodeid,
fslocation=fslocation)
# methods for ordering nodes
@property
def nodeid(self):
@@ -296,7 +316,7 @@ class Node(object):
except py.builtin._sysex:
raise
except:
failure = py.std.sys.exc_info()
failure = sys.exc_info()
setattr(self, exattrname, failure)
raise
setattr(self, attrname, res)
@@ -371,20 +391,24 @@ class Node(object):
fm = self.session._fixturemanager
if excinfo.errisinstance(fm.FixtureLookupError):
return excinfo.value.formatrepr()
tbfilter = True
if self.config.option.fulltrace:
style="long"
else:
self._prunetraceback(excinfo)
# XXX should excinfo.getrepr record all data and toterminal()
# process it?
tbfilter = False # prunetraceback already does it
if style == "auto":
style = "long"
# XXX should excinfo.getrepr record all data and toterminal() process it?
if style is None:
if self.config.option.tbstyle == "short":
style = "short"
else:
style = "long"
return excinfo.getrepr(funcargs=True,
showlocals=self.config.option.showlocals,
style=style)
style=style, tbfilter=tbfilter)
repr_failure = _repr_failure_py
@@ -393,10 +417,6 @@ class Collector(Node):
and thus iteratively build a tree.
"""
# the set of exceptions to interpret as "Skip the whole module" during
# collection
skip_exceptions = (Skipped,)
class CollectError(Exception):
""" an error during collection, contains a custom message. """
@@ -454,6 +474,14 @@ class Item(Node):
"""
nextitem = None
def __init__(self, name, parent=None, config=None, session=None):
super(Item, self).__init__(name, parent, config, session)
self._report_sections = []
def add_report_section(self, when, key, content):
if content:
self._report_sections.append((when, key, content))
def reportinfo(self):
return self.fspath, None, ""
@@ -538,9 +566,12 @@ class Session(FSCollector):
self.ihook.pytest_collectreport(report=rep)
self.trace.root.indent -= 1
if self._notfound:
errors = []
for arg, exc in self._notfound:
line = "(no name %r in any of %r)" % (arg, exc.args[0])
raise pytest.UsageError("not found: %s\n%s" %(arg, line))
errors.append("not found: %s\n%s" % (arg, line))
#XXX: test this
raise pytest.UsageError(*errors)
if not genitems:
return rep.result
else:
@@ -561,8 +592,7 @@ class Session(FSCollector):
# we are inside a make_report hook so
# we cannot directly pass through the exception
self._notfound.append((arg, sys.exc_info()[1]))
self.trace.root.indent -= 1
break
self.trace.root.indent -= 1
def _collect(self, arg):

View File

@@ -157,10 +157,10 @@ def pytest_configure(config):
class MarkGenerator:
""" Factory for :class:`MarkDecorator` objects - exposed as
a ``py.test.mark`` singleton instance. Example::
a ``pytest.mark`` singleton instance. Example::
import py
@py.test.mark.slowtest
@pytest.mark.slowtest
def test_function():
pass
@@ -169,7 +169,7 @@ class MarkGenerator:
def __getattr__(self, name):
if name[0] == "_":
raise AttributeError(name)
raise AttributeError("Marker name must NOT start with underscore")
if hasattr(self, '_config'):
self._check(name)
return MarkDecorator(name)
@@ -198,14 +198,32 @@ class MarkDecorator:
:ref:`retrieved by hooks as item keywords <excontrolskip>`.
MarkDecorator instances are often created like this::
mark1 = py.test.mark.NAME # simple MarkDecorator
mark2 = py.test.mark.NAME(name1=value) # parametrized MarkDecorator
mark1 = pytest.mark.NAME # simple MarkDecorator
mark2 = pytest.mark.NAME(name1=value) # parametrized MarkDecorator
and can then be applied as decorators to test functions::
@mark2
def test_function():
pass
When a MarkDecorator instance is called it does the following:
1. If called with a single class as its only positional argument and no
additional keyword arguments, it attaches itself to the class so it
gets applied automatically to all test cases found in that class.
2. If called with a single function as its only positional argument and
no additional keyword arguments, it attaches a MarkInfo object to the
function, containing all the arguments already stored internally in
the MarkDecorator.
3. When called in any other case, it performs a 'fake construction' call,
i.e. it returns a new MarkDecorator instance with the original
MarkDecorator's content updated with the arguments passed to this
call.
Note: The rules above prevent MarkDecorator objects from storing only a
single function or class reference as their positional argument with no
additional keyword or positional arguments.
"""
def __init__(self, name, args=None, kwargs=None):
self.name = name
@@ -224,7 +242,7 @@ class MarkDecorator:
def __call__(self, *args, **kwargs):
""" if passed a single callable argument: decorate it with mark info.
otherwise add *args/**kwargs in-place to mark information. """
if args:
if args and not kwargs:
func = args[0]
if len(args) == 1 and (istestfunc(func) or
hasattr(func, '__bases__')):

View File

@@ -59,7 +59,11 @@ def derive_importpath(import_path):
notset = object()
class Notset:
def __repr__(self):
return "<notset>"
notset = Notset()
class monkeypatch:
""" object keeping a record of setattr/item/env/syspath changes. """

View File

@@ -1,17 +1,27 @@
""" run test suites written for nose. """
import pytest, py
import sys
import py
import pytest
from _pytest import unittest
def get_skip_exceptions():
skip_classes = set()
for module_name in ('unittest', 'unittest2', 'nose'):
mod = sys.modules.get(module_name)
if hasattr(mod, 'SkipTest'):
skip_classes.add(mod.SkipTest)
return tuple(skip_classes)
def pytest_runtest_makereport(__multicall__, item, call):
SkipTest = getattr(sys.modules.get('nose', None), 'SkipTest', None)
if SkipTest:
if call.excinfo and call.excinfo.errisinstance(SkipTest):
# let's substitute the excinfo with a py.test.skip one
call2 = call.__class__(lambda:
pytest.skip(str(call.excinfo.value)), call.when)
call.excinfo = call2.excinfo
if call.excinfo and call.excinfo.errisinstance(get_skip_exceptions()):
# let's substitute the excinfo with a pytest.skip one
call2 = call.__class__(lambda:
pytest.skip(str(call.excinfo.value)), call.when)
call.excinfo = call2.excinfo
@pytest.mark.trylast
@@ -38,13 +48,8 @@ def teardown_nose(item):
# #call_optional(item._nosegensetup, 'teardown')
# del item.parent._nosegensetup
def pytest_make_collect_report(collector):
SkipTest = getattr(sys.modules.get('unittest', None), 'SkipTest', None)
if SkipTest is not None:
collector.skip_exceptions += (SkipTest,)
SkipTest = getattr(sys.modules.get('nose', None), 'SkipTest', None)
if SkipTest is not None:
collector.skip_exceptions += (SkipTest,)
if isinstance(collector, pytest.Generator):
call_optional(collector.obj, 'setup')

View File

@@ -1,8 +1,12 @@
""" interactive debugging with PDB, the Python Debugger. """
import pytest, py
from __future__ import absolute_import
import pdb
import sys
import pytest
import py
def pytest_addoption(parser):
group = parser.getgroup("general")
group._addoption('--pdb',
@@ -16,50 +20,37 @@ def pytest_configure(config):
if config.getvalue("usepdb"):
config.pluginmanager.register(PdbInvoke(), 'pdbinvoke')
old_trace = py.std.pdb.set_trace
old = (pdb.set_trace, pytestPDB._pluginmanager)
def fin():
py.std.pdb.set_trace = old_trace
py.std.pdb.set_trace = pytest.set_trace
pdb.set_trace, pytestPDB._pluginmanager = old
pdb.set_trace = pytest.set_trace
pytestPDB._pluginmanager = config.pluginmanager
config._cleanup.append(fin)
class pytestPDB:
""" Pseudo PDB that defers to the real pdb. """
item = None
collector = None
_pluginmanager = None
def set_trace(self):
""" invoke PDB set_trace debugging, dropping any IO capturing. """
frame = sys._getframe().f_back
item = self.item or self.collector
if item is not None:
capman = item.config.pluginmanager.getplugin("capturemanager")
out, err = capman.suspendcapture()
if hasattr(item, 'outerr'):
item.outerr = (item.outerr[0] + out, item.outerr[1] + err)
capman = None
if self._pluginmanager is not None:
capman = self._pluginmanager.getplugin("capturemanager")
if capman:
capman.suspendcapture(in_=True)
tw = py.io.TerminalWriter()
tw.line()
tw.sep(">", "PDB set_trace (IO-capturing turned off)")
py.std.pdb.Pdb().set_trace(frame)
pdb.Pdb().set_trace(frame)
def pdbitem(item):
pytestPDB.item = item
pytest_runtest_setup = pytest_runtest_call = pytest_runtest_teardown = pdbitem
@pytest.mark.tryfirst
def pytest_make_collect_report(__multicall__, collector):
try:
pytestPDB.collector = collector
return __multicall__.execute()
finally:
pytestPDB.collector = None
def pytest_runtest_makereport():
pytestPDB.item = None
class PdbInvoke:
def pytest_exception_interact(self, node, call, report):
return _enter_pdb(node, call.excinfo, report)
capman = node.config.pluginmanager.getplugin("capturemanager")
if capman:
capman.suspendcapture(in_=True)
_enter_pdb(node, call.excinfo, report)
def pytest_internalerror(self, excrepr, excinfo):
for line in str(excrepr).split("\n"):
@@ -87,7 +78,8 @@ def _enter_pdb(node, excinfo, rep):
def _postmortem_traceback(excinfo):
# A doctest.UnexpectedException is not useful for post_mortem.
# Use the underlying exception instead:
if isinstance(excinfo.value, py.std.doctest.UnexpectedException):
from doctest import UnexpectedException
if isinstance(excinfo.value, UnexpectedException):
return excinfo.value.exc_info[2]
else:
return excinfo._excinfo[2]
@@ -101,7 +93,6 @@ def _find_last_non_hidden_frame(stack):
def post_mortem(t):
pdb = py.std.pdb
class Pdb(pdb.Pdb):
def get_stack(self, f, t):
stack, i = pdb.Pdb.get_stack(self, f, t)

View File

@@ -1,15 +1,21 @@
""" (disabled by default) support for testing py.test and py.test plugins. """
import py, pytest
import sys, os
""" (disabled by default) support for testing pytest and pytest plugins. """
import inspect
import sys
import os
import codecs
import re
import time
import platform
from fnmatch import fnmatch
from _pytest.main import Session, EXIT_OK
import subprocess
import py
import pytest
from py.builtin import print_
from _pytest.core import HookRelay
from _pytest.main import Session, EXIT_OK
def get_public_names(l):
"""Only return names from iterator l without a leading underscore."""
@@ -87,10 +93,10 @@ class HookRecorder:
def _makecallparser(self, method):
name = method.__name__
args, varargs, varkw, default = py.std.inspect.getargspec(method)
args, varargs, varkw, default = inspect.getargspec(method)
if not args or args[0] != "self":
args.insert(0, 'self')
fspec = py.std.inspect.formatargspec(args, varargs, varkw, default)
fspec = inspect.formatargspec(args, varargs, varkw, default)
# we use exec because we want to have early type
# errors on wrong input arguments, using
# *args/**kwargs delays this and gives errors
@@ -122,7 +128,7 @@ class HookRecorder:
__tracebackhide__ = True
i = 0
entries = list(entries)
backlocals = py.std.sys._getframe(1).f_locals
backlocals = sys._getframe(1).f_locals
while entries:
name, check = entries.pop(0)
for ind, call in enumerate(self.calls[i:]):
@@ -137,7 +143,7 @@ class HookRecorder:
break
print_("NONAMEMATCH", name, "with", call)
else:
py.test.fail("could not find %r check %r" % (name, check))
pytest.fail("could not find %r check %r" % (name, check))
def popcall(self, name):
__tracebackhide__ = True
@@ -147,7 +153,7 @@ class HookRecorder:
return call
lines = ["could not find call %r, in:" % (name,)]
lines.extend([" %s" % str(x) for x in self.calls])
py.test.fail("\n".join(lines))
pytest.fail("\n".join(lines))
def getcall(self, name):
l = self.getcalls(name)
@@ -210,7 +216,7 @@ class TmpTestdir:
def finalize(self):
for p in self._syspathremove:
py.std.sys.path.remove(p)
sys.path.remove(p)
if hasattr(self, '_olddir'):
self._olddir.chdir()
# delete modules that have been loaded from tmpdir
@@ -246,8 +252,14 @@ class TmpTestdir:
ret = None
for name, value in items:
p = self.tmpdir.join(name).new(ext=ext)
source = py.builtin._totext(py.code.Source(value)).strip()
content = source.encode("utf-8") # + "\n"
source = py.code.Source(value)
def my_totext(s, encoding="utf-8"):
if py.builtin._isbytes(s):
s = py.builtin._totext(s, encoding=encoding)
return s
source_unicode = "\n".join([my_totext(line) for line in source.lines])
source = py.builtin._totext(source_unicode)
content = source.strip().encode("utf-8") # + "\n"
#content = content.rstrip() + "\n"
p.write(content, "wb")
if ret is None:
@@ -277,7 +289,7 @@ class TmpTestdir:
def syspathinsert(self, path=None):
if path is None:
path = self.tmpdir
py.std.sys.path.insert(0, str(path))
sys.path.insert(0, str(path))
self._syspathremove.append(str(path))
def mkdir(self, name):
@@ -420,9 +432,8 @@ class TmpTestdir:
env['PYTHONPATH'] = os.pathsep.join(filter(None, [
str(os.getcwd()), env.get('PYTHONPATH', '')]))
kw['env'] = env
#print "env", env
return py.std.subprocess.Popen(cmdargs,
stdout=stdout, stderr=stderr, **kw)
return subprocess.Popen(cmdargs,
stdout=stdout, stderr=stderr, **kw)
def run(self, *cmdargs):
return self._run(*cmdargs)
@@ -467,12 +478,12 @@ class TmpTestdir:
def _getpybinargs(self, scriptname):
if not self.request.config.getvalue("notoolsonpath"):
# XXX we rely on script refering to the correct environment
# we cannot use "(py.std.sys.executable,script)"
# becaue on windows the script is e.g. a py.test.exe
return (py.std.sys.executable, _pytest_fullpath,) # noqa
# XXX we rely on script referring to the correct environment
# we cannot use "(sys.executable,script)"
# because on windows the script is e.g. a py.test.exe
return (sys.executable, _pytest_fullpath,) # noqa
else:
py.test.skip("cannot run %r with --no-tools-on-path" % scriptname)
pytest.skip("cannot run %r with --no-tools-on-path" % scriptname)
def runpython(self, script, prepend=True):
if prepend:
@@ -490,7 +501,7 @@ class TmpTestdir:
def runpython_c(self, command):
command = self._getsysprepend() + command
return self.run(py.std.sys.executable, "-c", command)
return self.run(sys.executable, "-c", command)
def runpytest(self, *args):
p = py.path.local.make_numbered_dir(prefix="runpytest-",
@@ -509,15 +520,15 @@ class TmpTestdir:
def spawn_pytest(self, string, expect_timeout=10.0):
if self.request.config.getvalue("notoolsonpath"):
py.test.skip("--no-tools-on-path prevents running pexpect-spawn tests")
pytest.skip("--no-tools-on-path prevents running pexpect-spawn tests")
basetemp = self.tmpdir.mkdir("pexpect")
invoke = " ".join(map(str, self._getpybinargs("py.test")))
cmd = "%s --basetemp=%s %s" % (invoke, basetemp, string)
return self.spawn(cmd, expect_timeout=expect_timeout)
def spawn(self, cmd, expect_timeout=10.0):
pexpect = py.test.importorskip("pexpect", "3.0")
if hasattr(sys, 'pypy_version_info') and '64' in py.std.platform.machine():
pexpect = pytest.importorskip("pexpect", "3.0")
if hasattr(sys, 'pypy_version_info') and '64' in platform.machine():
pytest.skip("pypy-64 bit not supported")
if sys.platform == "darwin":
pytest.xfail("pexpect does not work reliably on darwin?!")
@@ -664,7 +675,7 @@ class LineMatcher:
def fnmatch_lines(self, lines2):
def show(arg1, arg2):
py.builtin.print_(arg1, arg2, file=py.std.sys.stderr)
py.builtin.print_(arg1, arg2, file=sys.stderr)
lines2 = self._getlines(lines2)
lines1 = self.lines[:]
nextline = None
@@ -688,4 +699,4 @@ class LineMatcher:
show(" and:", repr(nextline))
extralines.append(nextline)
else:
py.test.fail("remains unmatched: %r, see stderr" % (line,))
pytest.fail("remains unmatched: %r, see stderr" % (line,))

View File

@@ -11,7 +11,8 @@ cutdir = py.path.local(_pytest.__file__).dirpath()
NoneType = type(None)
NOTSET = object()
isfunction = inspect.isfunction
isclass = inspect.isclass
callable = py.builtin.callable
def getfslineno(obj):
@@ -44,7 +45,7 @@ class FixtureFunctionMarker:
self.ids = ids
def __call__(self, function):
if inspect.isclass(function):
if isclass(function):
raise ValueError(
"class fixtures not supported (may be in the future)")
function._pytestfixturefunction = self
@@ -213,18 +214,26 @@ def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
res = __multicall__.execute()
if res is not None:
return res
if inspect.isclass(obj):
if isclass(obj):
#if hasattr(collector.obj, 'unittest'):
# return # we assume it's a mixin class for a TestCase derived one
if collector.classnamefilter(name):
Class = collector._getcustomclass("Class")
return Class(name, parent=collector)
elif collector.funcnamefilter(name) and hasattr(obj, '__call__') and \
elif collector.funcnamefilter(name) and hasattr(obj, "__call__") and \
getfixturemarker(obj) is None:
if is_generator(obj):
return Generator(name, parent=collector)
else:
return list(collector._genfunctions(name, obj))
# mock seems to store unbound methods (issue473), let's normalize it
obj = getattr(obj, "__func__", obj)
if not isfunction(obj):
collector.warn(code="C2", message=
"cannot collect %r because it is not a function."
% name, )
return
if getattr(obj, "__test__", True):
if is_generator(obj):
return Generator(name, parent=collector)
else:
return list(collector._genfunctions(name, obj))
def is_generator(func):
try:
@@ -306,6 +315,9 @@ class PyCollector(PyobjMixin, pytest.Collector):
return True
def collect(self):
if not getattr(self.obj, "__test__", True):
return []
# NB. we avoid random getattrs and peek in the __dict__ instead
# (XXX originally introduced from a PyPy need, still true?)
dicts = [getattr(self.obj, '__dict__', {})]
@@ -372,22 +384,22 @@ def add_funcarg_pseudo_fixture_def(collector, metafunc, fixturemanager):
# collect funcargs of all callspecs into a list of values
arg2params = {}
arg2scope = {}
arg2fixturedefs = metafunc._arg2fixturedefs
for param_index, callspec in enumerate(metafunc._calls):
for callspec in metafunc._calls:
for argname, argvalue in callspec.funcargs.items():
arg2params.setdefault(argname, []).append(argvalue)
if argname not in arg2scope:
scopenum = callspec._arg2scopenum.get(argname, scopenum_function)
arg2scope[argname] = scopes[scopenum]
callspec.indices[argname] = param_index
for argname in callspec.funcargs:
assert argname not in callspec.params
callspec.params.update(callspec.funcargs)
callspec.params[argname] = argvalue
arg2params_list = arg2params.setdefault(argname, [])
callspec.indices[argname] = len(arg2params_list)
arg2params_list.append(argvalue)
if argname not in arg2scope:
scopenum = callspec._arg2scopenum.get(argname,
scopenum_function)
arg2scope[argname] = scopes[scopenum]
callspec.funcargs.clear()
# register artificial FixtureDef's so that later at test execution
# time we can rely on a proper FixtureDef to exist for fixture setup.
arg2fixturedefs = metafunc._arg2fixturedefs
for argname, valuelist in arg2params.items():
# if we have a scope that is higher than function we need
# to make sure we only ever create an according fixturedef on
@@ -450,8 +462,8 @@ class Module(pytest.File, PyCollector):
try:
mod = self.fspath.pyimport(ensuresyspath=True)
except SyntaxError:
excinfo = py.code.ExceptionInfo()
raise self.CollectError(excinfo.getrepr(style="short"))
raise self.CollectError(
py.code.ExceptionInfo().getrepr(style="short"))
except self.fspath.ImportMismatchError:
e = sys.exc_info()[1]
raise self.CollectError(
@@ -485,7 +497,7 @@ class Module(pytest.File, PyCollector):
fin = getattr(self.obj, 'teardown_module', None)
if fin is not None:
#XXX: nose compat hack, move to nose plugin
# if it takes a positional arg, its probably a py.test style one
# if it takes a positional arg, it's probably a pytest style one
# so we pass the current module object
if inspect.getargspec(fin)[0]:
finalizer = lambda: fin(self.obj)
@@ -498,10 +510,9 @@ class Class(PyCollector):
""" Collector for test methods. """
def collect(self):
if hasinit(self.obj):
pytest.skip("class %s.%s with __init__ won't get collected" % (
self.obj.__module__,
self.obj.__name__,
))
self.warn("C1", "cannot collect test class %r because it has a "
"__init__ constructor" % self.obj.__name__)
return []
return [self._getcustomclass("Instance")(name="()", parent=self)]
def setup(self):
@@ -567,6 +578,12 @@ class FunctionMixin(PyobjMixin):
if ntraceback == traceback:
ntraceback = ntraceback.cut(excludepath=cutdir)
excinfo.traceback = ntraceback.filter()
# issue364: mark all but first and last frames to
# only show a single-line message for each frame
if self.config.option.tbstyle == "auto":
if len(excinfo.traceback) > 2:
for entry in excinfo.traceback[1:-1]:
entry.set_repr_style('short')
def _repr_failure_py(self, excinfo, style="long"):
if excinfo.errisinstance(pytest.fail.Exception):
@@ -577,8 +594,10 @@ class FunctionMixin(PyobjMixin):
def repr_failure(self, excinfo, outerr=None):
assert outerr is None, "XXX outerr usage is deprecated"
return self._repr_failure_py(excinfo,
style=self.config.option.tbstyle)
style = self.config.option.tbstyle
if style == "auto":
style = "long"
return self._repr_failure_py(excinfo, style=style)
class Generator(FunctionMixin, PyCollector):
@@ -962,13 +981,39 @@ def raises(ExpectedException, *args, **kwargs):
>>> raises(ZeroDivisionError, "f(0)")
<ExceptionInfo ...>
Performance note:
-----------------
Similar to caught exception objects in Python, explicitly clearing
local references to returned ``py.code.ExceptionInfo`` objects can
help the Python interpreter speed up its garbage collection.
Clearing those references breaks a reference cycle
(``ExceptionInfo`` --> caught exception --> frame stack raising
the exception --> current frame stack --> local variables -->
``ExceptionInfo``) which makes Python keep all objects referenced
from that cycle (including all local variables in the current
frame) alive until the next cyclic garbage collection run. See the
official Python ``try`` statement documentation for more detailed
information.
"""
__tracebackhide__ = True
if ExpectedException is AssertionError:
# we want to catch a AssertionError
# replace our subclass with the builtin one
# see https://bitbucket.org/hpk42/pytest/issue/176/pytestraises
from _pytest.assertion.util import BuiltinAssertionError as ExpectedException
from _pytest.assertion.util import BuiltinAssertionError \
as ExpectedException
msg = ("exceptions must be old-style classes or"
" derived from BaseException, not %s")
if isinstance(ExpectedException, tuple):
for exc in ExpectedException:
if not inspect.isclass(exc):
raise TypeError(msg % type(exc))
elif not inspect.isclass(ExpectedException):
raise TypeError(msg % type(ExpectedException))
if not args:
return RaisesContext(ExpectedException)
@@ -1011,7 +1056,7 @@ class RaisesContext(object):
return issubclass(self.excinfo.type, self.ExpectedException)
#
# the basic py.test Function item
# the basic pytest Function item
#
class Function(FunctionMixin, pytest.Item, FuncargnamesCompatAttr):
@@ -1225,7 +1270,7 @@ class FixtureRequest(FuncargnamesCompatAttr):
on all function invocations.
:arg marker: a :py:class:`_pytest.mark.MarkDecorator` object
created by a call to ``py.test.mark.NAME(...)``.
created by a call to ``pytest.mark.NAME(...)``.
"""
try:
self.node.keywords[marker.markname] = marker
@@ -1300,7 +1345,7 @@ class FixtureRequest(FuncargnamesCompatAttr):
except FixtureLookupError:
if argname == "request":
class PseudoFixtureDef:
cached_result = (self, [0])
cached_result = (self, [0], None)
return PseudoFixtureDef
raise
result = self._getfuncargvalue(fixturedef)
@@ -1757,13 +1802,15 @@ class FixtureDef:
self._finalizer.append(finalizer)
def finish(self):
while self._finalizer:
func = self._finalizer.pop()
func()
try:
del self.cached_result
except AttributeError:
pass
while self._finalizer:
func = self._finalizer.pop()
func()
finally:
# even if finalization fails, we invalidate
# the cached fixture value
if hasattr(self, "cached_result"):
del self.cached_result
def execute(self, request):
# get required arguments and register our own finish()
@@ -1771,7 +1818,7 @@ class FixtureDef:
kwargs = {}
for argname in self.argnames:
fixturedef = request._get_active_fixturedef(argname)
result, arg_cache_key = fixturedef.cached_result
result, arg_cache_key, exc = fixturedef.cached_result
kwargs[argname] = result
if argname != "request":
fixturedef.addfinalizer(self.finish)
@@ -1779,13 +1826,12 @@ class FixtureDef:
my_cache_key = request.param_index
cached_result = getattr(self, "cached_result", None)
if cached_result is not None:
#print argname, "Found cached_result", cached_result
#print argname, "param_index", param_index
result, cache_key = cached_result
result, cache_key, err = cached_result
if my_cache_key == cache_key:
#print request.fixturename, "CACHE HIT", repr(my_cache_key)
return result
#print request.fixturename, "CACHE MISS"
if err is not None:
py.builtin._reraise(*err)
else:
return result
# we have a previous but differently parametrized fixture instance
# so we need to tear it down before creating a new one
self.finish()
@@ -1802,15 +1848,31 @@ class FixtureDef:
fixturefunc = getimfunc(self.func)
if fixturefunc != self.func:
fixturefunc = fixturefunc.__get__(request.instance)
result = call_fixture_func(fixturefunc, request, kwargs,
self.yieldctx)
self.cached_result = (result, my_cache_key)
try:
result = call_fixture_func(fixturefunc, request, kwargs,
self.yieldctx)
except Exception:
self.cached_result = (None, my_cache_key, sys.exc_info())
raise
self.cached_result = (result, my_cache_key, None)
return result
def __repr__(self):
return ("<FixtureDef name=%r scope=%r baseid=%r >" %
(self.argname, self.scope, self.baseid))
def num_mock_patch_args(function):
""" return number of arguments used up by mock arguments (if any) """
patchings = getattr(function, "patchings", None)
if not patchings:
return 0
mock = sys.modules.get("mock", sys.modules.get("unittest.mock", None))
if mock is not None:
return len([p for p in patchings
if not p.attribute_name and p.new is mock.DEFAULT])
return len(patchings)
def getfuncargnames(function, startindex=None):
# XXX merge with main.py's varnames
#assert not inspect.isclass(function)
@@ -1820,7 +1882,7 @@ def getfuncargnames(function, startindex=None):
if startindex is None:
startindex = inspect.ismethod(function) and 1 or 0
if realfunction != function:
startindex += len(getattr(function, "patchings", []))
startindex += num_mock_patch_args(function)
function = realfunction
argnames = inspect.getargs(py.code.getrawcode(function))[0]
defaults = getattr(function, 'func_defaults',

View File

@@ -1,7 +1,8 @@
""" recording warnings during test function execution. """
import py
import sys
import warnings
def pytest_funcarg__recwarn(request):
"""Return a WarningsRecorder instance that provides these methods:
@@ -13,7 +14,6 @@ def pytest_funcarg__recwarn(request):
on warning categories.
"""
if sys.version_info >= (2,7):
import warnings
oldfilters = warnings.filters[:]
warnings.simplefilter('default')
def reset_filters():
@@ -30,26 +30,24 @@ def deprecated_call(func, *args, **kwargs):
""" assert that calling ``func(*args, **kwargs)``
triggers a DeprecationWarning.
"""
warningmodule = py.std.warnings
l = []
oldwarn_explicit = getattr(warningmodule, 'warn_explicit')
oldwarn_explicit = getattr(warnings, 'warn_explicit')
def warn_explicit(*args, **kwargs):
l.append(args)
oldwarn_explicit(*args, **kwargs)
oldwarn = getattr(warningmodule, 'warn')
oldwarn = getattr(warnings, 'warn')
def warn(*args, **kwargs):
l.append(args)
oldwarn(*args, **kwargs)
warningmodule.warn_explicit = warn_explicit
warningmodule.warn = warn
warnings.warn_explicit = warn_explicit
warnings.warn = warn
try:
ret = func(*args, **kwargs)
finally:
warningmodule.warn_explicit = warn_explicit
warningmodule.warn = warn
warnings.warn_explicit = warn_explicit
warnings.warn = warn
if not l:
#print warningmodule
__tracebackhide__ = True
raise AssertionError("%r did not produce DeprecationWarning" %(func,))
return ret
@@ -65,7 +63,6 @@ class RecordedWarning:
class WarningsRecorder:
def __init__(self):
warningmodule = py.std.warnings
self.list = []
def showwarning(message, category, filename, lineno, line=0):
self.list.append(RecordedWarning(
@@ -76,8 +73,8 @@ class WarningsRecorder:
except TypeError:
# < python2.6
self.old_showwarning(message, category, filename, lineno)
self.old_showwarning = warningmodule.showwarning
warningmodule.showwarning = showwarning
self.old_showwarning = warnings.showwarning
warnings.showwarning = showwarning
def pop(self, cls=Warning):
""" pop the first recorded warning, raise exception if not exists."""
@@ -88,7 +85,6 @@ class WarningsRecorder:
assert 0, "%r not found in %r" %(cls, self.list)
#def resetregistry(self):
# import warnings
# warnings.onceregistry.clear()
# warnings.__warningregistry__.clear()
@@ -96,4 +92,4 @@ class WarningsRecorder:
self.list[:] = []
def finalize(self):
py.std.warnings.showwarning = self.old_showwarning
warnings.showwarning = self.old_showwarning

View File

@@ -1,7 +1,10 @@
""" basic collect and runtest protocol implementations """
import py, sys
import bdb
import sys
from time import time
import py
import pytest
from py._code.code import TerminalRepr
def pytest_namespace():
@@ -116,7 +119,7 @@ def check_interactive_exception(call, report):
return call.excinfo and not (
hasattr(report, "wasxfail") or
call.excinfo.errisinstance(skip.Exception) or
call.excinfo.errisinstance(py.std.bdb.BdbQuit))
call.excinfo.errisinstance(bdb.BdbQuit))
def call_runtest_hook(item, when, **kwds):
hookname = "pytest_runtest_" + when
@@ -133,14 +136,13 @@ class CallInfo:
self.when = when
self.start = time()
try:
try:
self.result = func()
except KeyboardInterrupt:
raise
except:
self.excinfo = py.code.ExceptionInfo()
finally:
self.result = func()
except KeyboardInterrupt:
self.stop = time()
raise
except:
self.excinfo = py.code.ExceptionInfo()
self.stop = time()
def __repr__(self):
if self.excinfo:
@@ -176,6 +178,11 @@ class BaseReport(object):
except UnicodeEncodeError:
out.line("<unprintable longrepr>")
def get_sections(self, prefix):
for name, content in self.sections:
if name.startswith(prefix):
yield prefix, content
passed = property(lambda x: x.outcome == "passed")
failed = property(lambda x: x.outcome == "failed")
skipped = property(lambda x: x.outcome == "skipped")
@@ -189,6 +196,7 @@ def pytest_runtest_makereport(item, call):
duration = call.stop-call.start
keywords = dict([(x,1) for x in item.keywords])
excinfo = call.excinfo
sections = []
if not call.excinfo:
outcome = "passed"
longrepr = None
@@ -196,7 +204,7 @@ def pytest_runtest_makereport(item, call):
if not isinstance(excinfo, py.code.ExceptionInfo):
outcome = "failed"
longrepr = excinfo
elif excinfo.errisinstance(py.test.skip.Exception):
elif excinfo.errisinstance(pytest.skip.Exception):
outcome = "skipped"
r = excinfo._getreprcrash()
longrepr = (str(r.path), r.lineno, r.message)
@@ -207,16 +215,18 @@ def pytest_runtest_makereport(item, call):
else: # exception in setup or teardown
longrepr = item._repr_failure_py(excinfo,
style=item.config.option.tbstyle)
for rwhen, key, content in item._report_sections:
sections.append(("Captured std%s %s" %(key, rwhen), content))
return TestReport(item.nodeid, item.location,
keywords, outcome, longrepr, when,
duration=duration)
sections, duration)
class TestReport(BaseReport):
""" Basic test report object (also used for setup and teardown calls if
they fail).
"""
def __init__(self, nodeid, location,
keywords, outcome, longrepr, when, sections=(), duration=0, **extra):
def __init__(self, nodeid, location, keywords, outcome,
longrepr, when, sections=(), duration=0, **extra):
#: normalized collection node id
self.nodeid = nodeid
@@ -265,7 +275,9 @@ def pytest_make_collect_report(collector):
if not call.excinfo:
outcome = "passed"
else:
if call.excinfo.errisinstance(collector.skip_exceptions):
from _pytest import nose
skip_exceptions = (Skipped,) + nose.get_skip_exceptions()
if call.excinfo.errisinstance(skip_exceptions):
outcome = "skipped"
r = collector._repr_failure_py(call.excinfo, "line").reprcrash
longrepr = (str(r.path), r.lineno, r.message)
@@ -282,7 +294,8 @@ def pytest_make_collect_report(collector):
class CollectReport(BaseReport):
def __init__(self, nodeid, outcome, longrepr, result, sections=(), **extra):
def __init__(self, nodeid, outcome, longrepr, result,
sections=(), **extra):
self.nodeid = nodeid
self.outcome = outcome
self.longrepr = longrepr
@@ -314,11 +327,10 @@ class SetupState(object):
""" attach a finalizer to the given colitem.
if colitem is None, this will add a finalizer that
is called at the end of teardown_all().
if colitem is a tuple, it will be used as a key
and needs an explicit call to _callfinalizers(key) later on.
"""
assert hasattr(finalizer, '__call__')
#assert colitem in self.stack
assert colitem and not isinstance(colitem, tuple)
assert py.builtin.callable(finalizer)
#assert colitem in self.stack # some unit tests don't setup stack :/
self._finalizers.setdefault(colitem, []).append(finalizer)
def _pop_and_teardown(self):
@@ -418,7 +430,7 @@ class Skipped(OutcomeException):
__module__ = 'builtins'
class Failed(OutcomeException):
""" raised from an explicit call to py.test.fail() """
""" raised from an explicit call to pytest.fail() """
__module__ = 'builtins'
class Exit(KeyboardInterrupt):
@@ -438,7 +450,7 @@ exit.Exception = Exit
def skip(msg=""):
""" skip an executing test with the given message. Note: it's usually
better to use the py.test.mark.skipif marker to declare a test to be
better to use the pytest.mark.skipif marker to declare a test to be
skipped under certain conditions like mismatching platforms or
dependencies. See the pytest_skipping plugin for details.
"""

View File

@@ -1,7 +1,10 @@
""" support for skip/xfail functions and markers. """
import py, pytest
import os
import sys
import traceback
import py
import pytest
def pytest_addoption(parser):
group = parser.getgroup("general")
@@ -26,18 +29,20 @@ def pytest_configure(config):
"http://pytest.org/latest/skipping.html"
)
config.addinivalue_line("markers",
"xfail(condition, reason=None, run=True): mark the the test function "
"xfail(condition, reason=None, run=True, raises=None): mark the the test function "
"as an expected failure if eval(condition) has a True value. "
"Optionally specify a reason for better reporting and run=False if "
"you don't even want to execute the test function. See "
"http://pytest.org/latest/skipping.html"
"you don't even want to execute the test function. If only specific "
"exception(s) are expected, you can list them in raises, and if the test fails "
"in other ways, it will be reported as a true failure. "
"See http://pytest.org/latest/skipping.html"
)
def pytest_namespace():
return dict(xfail=xfail)
class XFailed(pytest.fail.Exception):
""" raised from an explicit call to py.test.xfail() """
""" raised from an explicit call to pytest.xfail() """
def xfail(reason=""):
""" xfail an executing test or setup functions with the given reason."""
@@ -60,6 +65,12 @@ class MarkEvaluator:
def wasvalid(self):
return not hasattr(self, 'exc')
def invalidraise(self, exc):
raises = self.get('raises')
if not raises:
return
return not isinstance(exc, raises)
def istrue(self):
try:
return self._istrue()
@@ -71,7 +82,7 @@ class MarkEvaluator:
msg = [" " * (self.exc[1].offset + 4) + "^",]
msg.append("SyntaxError: invalid syntax")
else:
msg = py.std.traceback.format_exception_only(*self.exc[:2])
msg = traceback.format_exception_only(*self.exc[:2])
pytest.fail("Error evaluating %r expression\n"
" %s\n"
"%s"
@@ -79,7 +90,7 @@ class MarkEvaluator:
pytrace=False)
def _getglobals(self):
d = {'os': py.std.os, 'sys': py.std.sys, 'config': self.item.config}
d = {'os': os, 'sys': sys, 'config': self.item.config}
func = self.item.obj
try:
d.update(func.__globals__)
@@ -129,7 +140,7 @@ def pytest_runtest_setup(item):
return
evalskip = MarkEvaluator(item, 'skipif')
if evalskip.istrue():
py.test.skip(evalskip.getexplanation())
pytest.skip(evalskip.getexplanation())
item._evalxfail = MarkEvaluator(item, 'xfail')
check_xfail_no_run(item)
@@ -141,7 +152,7 @@ def check_xfail_no_run(item):
evalxfail = item._evalxfail
if evalxfail.istrue():
if not evalxfail.get('run', True):
py.test.xfail("[NOTRUN] " + evalxfail.getexplanation())
pytest.xfail("[NOTRUN] " + evalxfail.getexplanation())
def pytest_runtest_makereport(__multicall__, item, call):
if not isinstance(item, pytest.Function):
@@ -150,16 +161,16 @@ def pytest_runtest_makereport(__multicall__, item, call):
if hasattr(item, '_unexpectedsuccess'):
rep = __multicall__.execute()
if rep.when == "call":
# we need to translate into how py.test encodes xpass
# we need to translate into how pytest encodes xpass
rep.wasxfail = "reason: " + repr(item._unexpectedsuccess)
rep.outcome = "failed"
return rep
if not (call.excinfo and
call.excinfo.errisinstance(py.test.xfail.Exception)):
call.excinfo.errisinstance(pytest.xfail.Exception)):
evalxfail = getattr(item, '_evalxfail', None)
if not evalxfail:
return
if call.excinfo and call.excinfo.errisinstance(py.test.xfail.Exception):
if call.excinfo and call.excinfo.errisinstance(pytest.xfail.Exception):
if not item.config.getvalue("runxfail"):
rep = __multicall__.execute()
rep.wasxfail = "reason: " + call.excinfo.value.msg
@@ -171,7 +182,11 @@ def pytest_runtest_makereport(__multicall__, item, call):
if not item.config.option.runxfail:
if evalxfail.wasvalid() and evalxfail.istrue():
if call.excinfo:
rep.outcome = "skipped"
if evalxfail.invalidraise(call.excinfo.value):
rep.outcome = "failed"
return rep
else:
rep.outcome = "skipped"
elif call.when == "call":
rep.outcome = "failed"
else:
@@ -186,7 +201,7 @@ def pytest_report_teststatus(report):
if report.skipped:
return "xfailed", "x", "xfail"
elif report.failed:
return "xpassed", "X", "XPASS"
return "xpassed", "X", ("XPASS", {'yellow': True})
# called by the terminalreporter instance/plugin
def pytest_terminal_summary(terminalreporter):

View File

@@ -5,6 +5,8 @@ This is a good source for looking at the various reporting hooks.
import pytest
import py
import sys
import time
def pytest_addoption(parser):
group = parser.getgroup("terminal reporting", "reporting", after="general")
@@ -15,7 +17,7 @@ def pytest_addoption(parser):
group._addoption('-r',
action="store", dest="reportchars", default=None, metavar="chars",
help="show extra test summary info as specified by chars (f)ailed, "
"(E)error, (s)skipped, (x)failed, (X)passed.")
"(E)error, (s)skipped, (x)failed, (X)passed (w)warnings.")
group._addoption('-l', '--showlocals',
action="store_true", dest="showlocals", default=False,
help="show locals in tracebacks (disabled by default).")
@@ -23,8 +25,8 @@ def pytest_addoption(parser):
action="store", dest="report", default=None, metavar="opts",
help="(deprecated, use -r)")
group._addoption('--tb', metavar="style",
action="store", dest="tbstyle", default='long',
choices=['long', 'short', 'no', 'line', 'native'],
action="store", dest="tbstyle", default='auto',
choices=['auto', 'long', 'short', 'no', 'line', 'native'],
help="traceback print mode (long/short/line/native/no).")
group._addoption('--fulltrace', '--full-trace',
action="store_true", default=False,
@@ -49,7 +51,7 @@ def getreportopt(config):
optvalue = config.option.report
if optvalue:
py.builtin.print_("DEPRECATED: use -r instead of --report option.",
file=py.std.sys.stderr)
file=sys.stderr)
if optvalue:
for setting in optvalue.split(","):
setting = setting.strip()
@@ -75,6 +77,14 @@ def pytest_report_teststatus(report):
letter = "f"
return report.outcome, letter, report.outcome.upper()
class WarningReport:
def __init__(self, code, message, nodeid=None, fslocation=None):
self.code = code
self.message = message
self.nodeid = nodeid
self.fslocation = fslocation
class TerminalReporter:
def __init__(self, config, file=None):
self.config = config
@@ -87,7 +97,7 @@ class TerminalReporter:
self.stats = {}
self.startdir = self.curdir = py.path.local()
if file is None:
file = py.std.sys.stdout
file = sys.stdout
self._tw = self.writer = py.io.TerminalWriter(file)
if self.config.option.color == 'yes':
self._tw.hasmarkup = True
@@ -128,7 +138,8 @@ class TerminalReporter:
self._tw.write(content, **markup)
def write_line(self, line, **markup):
line = str(line)
if not py.builtin._istext(line):
line = py.builtin.text(line, errors="replace")
self.ensure_newline()
self._tw.line(line, **markup)
@@ -147,10 +158,16 @@ class TerminalReporter:
self._tw.line(msg, **kw)
def pytest_internalerror(self, excrepr):
for line in str(excrepr).split("\n"):
for line in py.builtin.text(excrepr).split("\n"):
self.write_line("INTERNALERROR> " + line)
return 1
def pytest_logwarning(self, code, fslocation, message, nodeid):
warnings = self.stats.setdefault("warnings", [])
warning = WarningReport(code=code, fslocation=fslocation,
message=message, nodeid=nodeid)
warnings.append(warning)
def pytest_plugin_registered(self, plugin):
if self.config.option.traceconfig:
msg = "PLUGIN registered: %s" % (plugin,)
@@ -250,7 +267,7 @@ class TerminalReporter:
@pytest.mark.trylast
def pytest_sessionstart(self, session):
self._sessionstarttime = py.std.time.time()
self._sessionstarttime = time.time()
if not self.showheader:
return
self.write_sep("=", "test session starts", bold=True)
@@ -259,7 +276,7 @@ class TerminalReporter:
if hasattr(sys, 'pypy_version_info'):
verinfo = ".".join(map(str, sys.pypy_version_info[:3]))
msg += "[pypy-%s-%s]" % (verinfo, sys.pypy_version_info[3])
msg += " -- pytest-%s" % (py.test.__version__)
msg += " -- py-%s -- pytest-%s" % (py.__version__, pytest.__version__)
if self.verbosity > 0 or self.config.option.debug or \
getattr(self.config.option, 'pastebin', None):
msg += " -- " + str(sys.executable)
@@ -334,7 +351,7 @@ class TerminalReporter:
if exitstatus in (0, 1, 2, 4):
self.summary_errors()
self.summary_failures()
self.summary_hints()
self.summary_warnings()
self.config.hook.pytest_terminal_summary(terminalreporter=self)
if exitstatus == 2:
self._report_keyboardinterrupt()
@@ -365,11 +382,10 @@ class TerminalReporter:
fspath = "%s <- %s" % (collect_fspath, fspath)
if fspath:
line = str(fspath)
if lineno is not None:
lineno += 1
line += ":" + str(lineno)
if domain:
line += ": " + str(domain)
split = str(domain).split('[')
split[0] = split[0].replace('.', '::') # don't replace '.' in params
line += "::" + '['.join(split)
else:
line = "[location]"
return line + " "
@@ -400,10 +416,15 @@ class TerminalReporter:
l.append(x)
return l
def summary_hints(self):
if self.config.option.traceconfig:
for hint in self.config.pluginmanager._hints:
self._tw.line("hint: %s" % hint)
def summary_warnings(self):
if self.hasopt("w"):
warnings = self.stats.get("warnings")
if not warnings:
return
self.write_sep("=", "warning summary")
for w in warnings:
self._tw.line("W%s %s %s" % (w.code,
w.fslocation, w.message))
def summary_failures(self):
if self.config.option.tbstyle != "no":
@@ -447,9 +468,10 @@ class TerminalReporter:
self._tw.line(content)
def summary_stats(self):
session_duration = py.std.time.time() - self._sessionstarttime
session_duration = time.time() - self._sessionstarttime
keys = "failed passed skipped deselected xfailed xpassed".split()
keys = ("failed passed skipped deselected "
"xfailed xpassed warnings").split()
for key in self.stats.keys():
if key not in keys:
keys.append(key)

View File

@@ -1,7 +1,11 @@
""" support for providing temporary directories to test functions. """
import pytest, py
import re
import pytest
import py
from _pytest.monkeypatch import monkeypatch
class TempdirHandler:
def __init__(self, config):
self.config = config
@@ -63,7 +67,7 @@ def tmpdir(request):
path object.
"""
name = request.node.name
name = py.std.re.sub("[\W]", "_", name)
name = re.sub("[\W]", "_", name)
MAXVAL = 30
if len(name) > MAXVAL:
name = name[:MAXVAL]

View File

@@ -1,27 +1,25 @@
""" discovery and running of std-library "unittest" style tests. """
import pytest, py
from __future__ import absolute_import
import traceback
import sys
import pytest
import py
# for transfering markers
from _pytest.python import transfer_markers
def is_unittest(obj):
"""Is obj a subclass of unittest.TestCase?"""
unittest = sys.modules.get('unittest')
if unittest is None:
return # nobody can have derived unittest.TestCase
try:
return issubclass(obj, unittest.TestCase)
except KeyboardInterrupt:
raise
except:
return False
def pytest_pycollect_makeitem(collector, name, obj):
if is_unittest(obj):
return UnitTestCase(name, parent=collector)
# has unittest been imported and is obj a subclass of its TestCase?
try:
if not issubclass(obj, sys.modules["unittest"].TestCase):
return
except Exception:
return
# yes, so let's collect it
return UnitTestCase(name, parent=collector)
class UnitTestCase(pytest.Class):
@@ -41,10 +39,13 @@ class UnitTestCase(pytest.Class):
super(UnitTestCase, self).setup()
def collect(self):
self.session._fixturemanager.parsefactories(self, unittest=True)
loader = py.std.unittest.TestLoader()
module = self.getparent(pytest.Module).obj
from unittest import TestLoader
cls = self.obj
if not getattr(cls, "__test__", True):
return
self.session._fixturemanager.parsefactories(self, unittest=True)
loader = TestLoader()
module = self.getparent(pytest.Module).obj
foundsomething = False
for name in loader.getTestCaseNames(self.obj):
x = getattr(self.obj, name)
@@ -88,7 +89,7 @@ class TestCaseFunction(pytest.Function):
except TypeError:
try:
try:
l = py.std.traceback.format_exception(*rawexcinfo)
l = traceback.format_exception(*rawexcinfo)
l.insert(0, "NOTE: Incompatible Exception Representation, "
"displaying natively:\n\n")
pytest.fail("".join(l), pytrace=False)
@@ -154,7 +155,7 @@ def pytest_runtest_protocol(item, __multicall__):
if isinstance(item, TestCaseFunction):
if 'twisted.trial.unittest' in sys.modules:
ut = sys.modules['twisted.python.failure']
Failure__init__ = ut.Failure.__init__.im_func
Failure__init__ = ut.Failure.__init__
check_testcase_implements_trial_reporter()
def excstore(self, exc_value=None, exc_type=None, exc_tb=None,
captureVars=None):

View File

@@ -2,10 +2,10 @@ import sys
if __name__ == '__main__':
import cProfile
import py
import pytest
import pstats
script = sys.argv[1] if len(sys.argv) > 1 else "empty.py"
stats = cProfile.run('py.test.cmdline.main([%r])' % script, 'prof')
script = sys.argv[1:] if len(sys.argv) > 1 else "empty.py"
stats = cProfile.run('pytest.cmdline.main(%r)' % script, 'prof')
p = pstats.Stats("prof")
p.strip_dirs()
p.sort_stats('cumulative')

View File

@@ -15,5 +15,4 @@
})();
</script>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
{% endblock %}

View File

@@ -1,11 +1,11 @@
<h3>Useful Links</h3>
<ul>
<li><a href="{{ pathto('index') }}">The pytest Website</a></li>
<li><a href="{{ pathto('contributing') }}">Contribution Guide</a></li>
<li><a href="https://pypi.python.org/pypi/pytest">pytest @ PyPI</a></li>
<li><a href="https://bitbucket.org/hpk42/pytest/">pytest @ Bitbucket</a></li>
<li><a href="https://github.com/hpk42/pytest/">pytest @ github</a></li>
<li><a href="http://pytest.org/latest/plugins_index/index.html">3rd party plugins</a></li>
<li><a href="https://bitbucket.org/hpk42/pytest/issues?status=new&status=open">Issue Tracker</a></li>
<li><a href="http://pytest.org/latest/pytest.pdf">PDF Documentation</a>
</ul>
<g:plusone></g:plusone>

View File

@@ -5,7 +5,6 @@
<link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
{% endif %}
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
<link href='http://fonts.googleapis.com/css?family=Gudea|Gudea' rel='stylesheet' type='text/css'>
{% endblock %}
{%- block relbar2 %}{% endblock %}
{% block header %}

View File

@@ -6,12 +6,13 @@
* :license: Flask Design License, see LICENSE for details.
*/
{% set page_width = '940px' %}
{% set page_width = '1020px' %}
{% set sidebar_width = '220px' %}
{% set base_font = '"Gudea", sans-serif' %}
{% set header_font = '"Gudea", sans-serif' %}
{% set link_color = '#490' %}
{% set link_hover_color = '#9c0' %}
/* orange of logo is #d67c29 but we use black for links for now */
{% set link_color = '#000' %}
{% set link_hover_color = '#000' %}
{% set base_font = 'sans-serif' %}
{% set header_font = 'sans-serif' %}
@import url("basic.css");

View File

@@ -5,6 +5,10 @@ Release announcements
.. toctree::
:maxdepth: 2
release-2.6.2
release-2.6.1
release-2.6.0
release-2.5.2
release-2.5.1
release-2.5.0
release-2.4.2

View File

@@ -0,0 +1,64 @@
pytest-2.5.2: fixes
===========================================================================
pytest is a mature Python testing tool with more than a 1000 tests
against itself, passing on many different interpreters and platforms.
The 2.5.2 release fixes a few bugs with two maybe-bugs remaining and
actively being worked on (and waiting for the bug reporter's input).
We also have a new contribution guide thanks to Piotr Banaszkiewicz
and others.
See docs at:
http://pytest.org
As usual, you can upgrade from pypi via::
pip install -U pytest
Thanks to the following people who contributed to this release:
Anatoly Bubenkov
Ronny Pfannschmidt
Floris Bruynooghe
Bruno Oliveira
Andreas Pelme
Jurko Gospodnetić
Piotr Banaszkiewicz
Simon Liedtke
lakka
Lukasz Balcerzak
Philippe Muller
Daniel Hahler
have fun,
holger krekel
2.5.2
-----------------------------------
- fix issue409 -- better interoperate with cx_freeze by not
trying to import from collections.abc which causes problems
for py27/cx_freeze. Thanks Wolfgang L. for reporting and tracking it down.
- fixed docs and code to use "pytest" instead of "py.test" almost everywhere.
Thanks Jurko Gospodnetic for the complete PR.
- fix issue425: mention at end of "py.test -h" that --markers
and --fixtures work according to specified test path (or current dir)
- fix issue413: exceptions with unicode attributes are now printed
correctly also on python2 and with pytest-xdist runs. (the fix
requires py-1.4.20)
- copy, cleanup and integrate py.io capture
from pylib 1.4.20.dev2 (rev 13d9af95547e)
- address issue416: clarify docs as to conftest.py loading semantics
- fix issue429: comparing byte strings with non-ascii chars in assert
expressions now work better. Thanks Floris Bruynooghe.
- make capfd/capsys.capture private, its unused and shouldnt be exposed

View File

@@ -0,0 +1,153 @@
pytest-2.6.0: shorter tracebacks, new warning system, test runner compat
===========================================================================
pytest is a mature Python testing tool with more than a 1000 tests
against itself, passing on many different interpreters and platforms.
The 2.6.0 release should be drop-in backward compatible to 2.5.2 and
fixes a number of bugs and brings some new features, mainly:
- shorter tracebacks by default: only the first (test function) entry
and the last (failure location) entry are shown, the ones between
only in "short" format. Use ``--tb=long`` to get back the old
behaviour of showing "long" entries everywhere.
- a new warning system which reports oddities during collection
and execution. For example, ignoring collecting Test* classes with an
``__init__`` now produces a warning.
- various improvements to nose/mock/unittest integration
Note also that 2.6.0 departs with the "zero reported bugs" policy
because it has been too hard to keep up with it, unfortunately.
Instead we are for now rather bound to work on "upvoted" issues in
the https://bitbucket.org/hpk42/pytest/issues?status=new&status=open&sort=-votes
issue tracker.
See docs at:
http://pytest.org
As usual, you can upgrade from pypi via::
pip install -U pytest
Thanks to all who contributed, among them:
Benjamin Peterson
Jurko Gospodnetić
Floris Bruynooghe
Marc Abramowitz
Marc Schlaich
Trevor Bekolay
Bruno Oliveira
Alex Groenholm
have fun,
holger krekel
2.6.0
-----------------------------------
- fix issue537: Avoid importing old assertion reinterpretation code by default.
Thanks Benjamin Peterson.
- fix issue364: shorten and enhance tracebacks representation by default.
The new "--tb=auto" option (default) will only display long tracebacks
for the first and last entry. You can get the old behaviour of printing
all entries as long entries with "--tb=long". Also short entries by
default are now printed very similarly to "--tb=native" ones.
- fix issue514: teach assertion reinterpretation about private class attributes
Thanks Benjamin Peterson.
- change -v output to include full node IDs of tests. Users can copy
a node ID from a test run, including line number, and use it as a
positional argument in order to run only a single test.
- fix issue 475: fail early and comprehensible if calling
pytest.raises with wrong exception type.
- fix issue516: tell in getting-started about current dependencies.
- cleanup setup.py a bit and specify supported versions. Thanks Jurko
Gospodnetic for the PR.
- change XPASS colour to yellow rather then red when tests are run
with -v.
- fix issue473: work around mock putting an unbound method into a class
dict when double-patching.
- fix issue498: if a fixture finalizer fails, make sure that
the fixture is still invalidated.
- fix issue453: the result of the pytest_assertrepr_compare hook now gets
it's newlines escaped so that format_exception does not blow up.
- internal new warning system: pytest will now produce warnings when
it detects oddities in your test collection or execution.
Warnings are ultimately sent to a new pytest_logwarning hook which is
currently only implemented by the terminal plugin which displays
warnings in the summary line and shows more details when -rw (report on
warnings) is specified.
- change skips into warnings for test classes with an __init__ and
callables in test modules which look like a test but are not functions.
- fix issue436: improved finding of initial conftest files from command
line arguments by using the result of parse_known_args rather than
the previous flaky heuristics. Thanks Marc Abramowitz for tests
and initial fixing approaches in this area.
- fix issue #479: properly handle nose/unittest(2) SkipTest exceptions
during collection/loading of test modules. Thanks to Marc Schlaich
for the complete PR.
- fix issue490: include pytest_load_initial_conftests in documentation
and improve docstring.
- fix issue472: clarify that ``pytest.config.getvalue()`` cannot work
if it's triggered ahead of command line parsing.
- merge PR123: improved integration with mock.patch decorator on tests.
- fix issue412: messing with stdout/stderr FD-level streams is now
captured without crashes.
- fix issue483: trial/py33 works now properly. Thanks Daniel Grana for PR.
- improve example for pytest integration with "python setup.py test"
which now has a generic "-a" or "--pytest-args" option where you
can pass additional options as a quoted string. Thanks Trevor Bekolay.
- simplified internal capturing mechanism and made it more robust
against tests or setups changing FD1/FD2, also better integrated
now with pytest.pdb() in single tests.
- improvements to pytest's own test-suite leakage detection, courtesy of PRs
from Marc Abramowitz
- fix issue492: avoid leak in test_writeorg. Thanks Marc Abramowitz.
- fix issue493: don't run tests in doc directory with ``python setup.py test``
(use tox -e doctesting for that)
- fix issue486: better reporting and handling of early conftest loading failures
- some cleanup and simplification of internal conftest handling.
- work a bit harder to break reference cycles when catching exceptions.
Thanks Jurko Gospodnetic.
- fix issue443: fix skip examples to use proper comparison. Thanks Alex
Groenholm.
- support nose-style ``__test__`` attribute on modules, classes and
functions, including unittest-style Classes. If set to False, the
test will not be collected.
- fix issue512: show "<notset>" for arguments which might not be set
in monkeypatch plugin. Improves output in documentation.
- avoid importing "py.test" (an old alias module for "pytest")

View File

@@ -0,0 +1,59 @@
pytest-2.6.1: fixes and new xfail feature
===========================================================================
pytest is a mature Python testing tool with more than a 1100 tests
against itself, passing on many different interpreters and platforms.
The 2.6.1 release is drop-in compatible to 2.5.2 and actually fixes some
regressions introduced with 2.6.0. It also brings a little feature
to the xfail marker which now recognizes expected exceptions,
see the CHANGELOG below.
See docs at:
http://pytest.org
As usual, you can upgrade from pypi via::
pip install -U pytest
Thanks to all who contributed, among them:
Floris Bruynooghe
Bruno Oliveira
Nicolas Delaby
have fun,
holger krekel
Changes 2.6.1
=================
- No longer show line numbers in the --verbose output, the output is now
purely the nodeid. The line number is still shown in failure reports.
Thanks Floris Bruynooghe.
- fix issue437 where assertion rewriting could cause pytest-xdist slaves
to collect different tests. Thanks Bruno Oliveira.
- fix issue555: add "errors" attribute to capture-streams to satisfy
some distutils and possibly other code accessing sys.stdout.errors.
- fix issue547 capsys/capfd also work when output capturing ("-s") is disabled.
- address issue170: allow pytest.mark.xfail(...) to specify expected exceptions via
an optional "raises=EXC" argument where EXC can be a single exception
or a tuple of exception classes. Thanks David Mohr for the complete
PR.
- fix integration of pytest with unittest.mock.patch decorator when
it uses the "new" argument. Thanks Nicolas Delaby for test and PR.
- fix issue with detecting conftest files if the arguments contain
"::" node id specifications (copy pasted from "-v" output)
- fix issue544 by only removing "@NUM" at the end of "::" separated parts
and if the part has an ".py" extension
- don't use py.std import helper, rather import things directly.
Thanks Bruno Oliveira.

View File

@@ -0,0 +1,52 @@
pytest-2.6.2: few fixes and cx_freeze support
===========================================================================
pytest is a mature Python testing tool with more than a 1100 tests
against itself, passing on many different interpreters and platforms.
This release is drop-in compatible to 2.5.2 and 2.6.X. It also
brings support for including pytest with cx_freeze or similar
freezing tools into your single-file app distribution. For details
see the CHANGELOG below.
See docs at:
http://pytest.org
As usual, you can upgrade from pypi via::
pip install -U pytest
Thanks to all who contributed, among them:
Floris Bruynooghe
Benjamin Peterson
Bruno Oliveira
have fun,
holger krekel
2.6.2
-----------
- Added function pytest.freeze_includes(), which makes it easy to embed
pytest into executables using tools like cx_freeze.
See docs for examples and rationale. Thanks Bruno Oliveira.
- Improve assertion rewriting cache invalidation precision.
- fixed issue561: adapt autouse fixture example for python3.
- fixed issue453: assertion rewriting issue with __repr__ containing
"\n{", "\n}" and "\n~".
- fix issue560: correctly display code if an "else:" or "finally:" is
followed by statements on the same line.
- Fix example in monkeypatch documentation, thanks t-8ch.
- fix issue572: correct tmpdir doc example for python3.
- Do not mark as universal wheel because Python 2.6 is different from
other builds due to the extra argparse dependency. Fixes issue566.
Thanks sontek.

View File

@@ -1,7 +1,7 @@
.. _apiref:
py.test reference documentation
pytest reference documentation
================================================
.. toctree::

View File

@@ -10,7 +10,7 @@ The writing and reporting of assertions in tests
Asserting with the ``assert`` statement
---------------------------------------------------------
``py.test`` allows you to use the standard python ``assert`` for verifying
``pytest`` allows you to use the standard python ``assert`` for verifying
expectations and values in Python tests. For example, you can write the
following::
@@ -26,7 +26,7 @@ you will see the return value of the function call::
$ py.test test_assert1.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 1 items
test_assert1.py F
@@ -42,7 +42,7 @@ you will see the return value of the function call::
test_assert1.py:5: AssertionError
========================= 1 failed in 0.01 seconds =========================
py.test has support for showing the values of the most common subexpressions
``pytest`` has support for showing the values of the most common subexpressions
including calls, attributes, comparisons, and binary and unary
operators. (See :ref:`tbreportdemo`). This allows you to use the
idiomatic python constructs without boilerplate code while not losing
@@ -95,6 +95,22 @@ asserts that the given ``ExpectedException`` is raised. The reporter will
provide you with helpful output in case of failures such as *no
exception* or *wrong exception*.
Note that it is also possible to specify a "raises" argument to
``pytest.mark.xfail``, which checks that the test is failing in a more
specific way than just having any exception raised::
@pytest.mark.xfail(raises=IndexError)
def test_f():
f()
Using ``pytest.raises`` is likely to be better for cases where you are testing
exceptions your own code is deliberately raising, whereas using
``@pytest.mark.xfail`` with a check function is probably better for something
like documenting unfixed bugs (where the test describes what "should" happen)
or bugs in dependencies.
.. _newreport:
Making use of context-sensitive comparisons
@@ -102,7 +118,7 @@ Making use of context-sensitive comparisons
.. versionadded:: 2.0
py.test has rich support for providing context-sensitive information
``pytest`` has rich support for providing context-sensitive information
when it encounters comparisons. For example::
# content of test_assert2.py
@@ -116,7 +132,7 @@ if you run this module::
$ py.test test_assert2.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 1 items
test_assert2.py F
@@ -175,21 +191,21 @@ now, given this test module::
f2 = Foo(2)
assert f1 == f2
you can run the test module and get the custom output defined in
you can run the test module and get the custom output defined in
the conftest file::
$ py.test -q test_foocompare.py
F
================================= FAILURES =================================
_______________________________ test_compare _______________________________
def test_compare():
f1 = Foo(1)
f2 = Foo(2)
> assert f1 == f2
E assert Comparing Foo instances:
E vals: 1 != 2
test_foocompare.py:8: AssertionError
1 failed in 0.01 seconds
@@ -205,33 +221,33 @@ Advanced assertion introspection
Reporting details about a failing assertion is achieved either by rewriting
assert statements before they are run or re-evaluating the assert expression and
recording the intermediate values. Which technique is used depends on the
location of the assert, py.test's configuration, and Python version being used
to run py.test. Note that for assert statements with a manually provided
location of the assert, ``pytest`` configuration, and Python version being used
to run ``pytest``. Note that for assert statements with a manually provided
message, i.e. ``assert expr, message``, no assertion introspection takes place
and the manually provided message will be rendered in tracebacks.
By default, if the Python version is greater than or equal to 2.6, py.test
By default, if the Python version is greater than or equal to 2.6, ``pytest``
rewrites assert statements in test modules. Rewritten assert statements put
introspection information into the assertion failure message. py.test only
introspection information into the assertion failure message. ``pytest`` only
rewrites test modules directly discovered by its test collection process, so
asserts in supporting modules which are not themselves test modules will not be
rewritten.
.. note::
py.test rewrites test modules on import. It does this by using an import hook
to write a new pyc files. Most of the time this works transparently. However,
if you are messing with import yourself, the import hook may interfere. If
this is the case, simply use ``--assert=reinterp`` or
``pytest`` rewrites test modules on import. It does this by using an import
hook to write a new pyc files. Most of the time this works transparently.
However, if you are messing with import yourself, the import hook may
interfere. If this is the case, simply use ``--assert=reinterp`` or
``--assert=plain``. Additionally, rewriting will fail silently if it cannot
write new pycs, i.e. in a read-only filesystem or a zipfile.
If an assert statement has not been rewritten or the Python version is less than
2.6, py.test falls back on assert reinterpretation. In assert reinterpretation,
py.test walks the frame of the function containing the assert statement to
discover sub-expression results of the failing assert statement. You can force
py.test to always use assertion reinterpretation by passing the
``--assert=reinterp`` option.
2.6, ``pytest`` falls back on assert reinterpretation. In assert
reinterpretation, ``pytest`` walks the frame of the function containing the
assert statement to discover sub-expression results of the failing assert
statement. You can force ``pytest`` to always use assertion reinterpretation by
passing the ``--assert=reinterp`` option.
Assert reinterpretation has a caveat not present with assert rewriting: If
evaluating the assert expression has side effects you may get a warning that the
@@ -250,7 +266,7 @@ easy to rewrite the assertion and avoid any trouble::
All assert introspection can be turned off by passing ``--assert=plain``.
For further information, Benjamin Peterson wrote up `Behind the scenes of py.test's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_.
For further information, Benjamin Peterson wrote up `Behind the scenes of pytest's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_.
.. versionadded:: 2.1
Add assert rewriting as an alternate introspection technique.

View File

@@ -1,188 +0,0 @@
**Test classes, modules or whole projects can make use of
one or more fixtures**. All required fixture functions will execute
before a test from the specifying context executes. As You can use this
to make tests operate from a pre-initialized directory or with
certain environment variables or with pre-configured global application
settings.
For example, the Django_ project requires database
initialization to be able to import from and use its model objects.
For that, the `pytest-django`_ plugin provides fixtures which your
project can then easily depend or extend on, simply by referencing the
name of the particular fixture.
Fixture functions have limited visilibity which depends on where they
are defined. If they are defined on a test class, only its test methods
may use it. A fixture defined in a module can only be used
from that test module. A fixture defined in a conftest.py file
can only be used by the tests below the directory of that file.
Lastly, plugins can define fixtures which are available across all
projects.
Python, Java and many other languages support a so called xUnit_ style
for providing a fixed state, `test fixtures`_, for running tests. It
typically involves calling a autouse function ahead and a teardown
function after test execute. In 2005 pytest introduced a scope-specific
model of automatically detecting and calling autouse and teardown
functions on a per-module, class or function basis. The Python unittest
package and nose have subsequently incorporated them. This model
remains supported by pytest as :ref:`classic xunit`.
One property of xunit fixture functions is that they work implicitely
by preparing global state or setting attributes on TestCase objects.
By contrast, pytest provides :ref:`funcargs` which allow to
dependency-inject application test state into test functions or
methods as function arguments. If your application is sufficiently modular
or if you are creating a new project, we recommend you now rather head over to
:ref:`funcargs` instead because many pytest users agree that using this
paradigm leads to better application and test organisation.
However, not all programs and frameworks work and can be tested in
a fully modular way. They rather require preparation of global state
like database autouse on which further fixtures like preparing application
specific tables or wrapping tests in transactions can take place. For those
needs, pytest-2.3 now supports new **fixture functions** which come with
a ton of improvements over classic xunit fixture writing. Fixture functions:
- allow to separate different autouse concerns into multiple modular functions
- can receive and fully interoperate with :ref:`funcargs <resources>`,
- are called multiple times if its funcargs are parametrized,
- don't need to be defined directly in your test classes or modules,
they can also be defined in a plugin or :ref:`conftest.py <conftest.py>` files and get called
- are called on a per-session, per-module, per-class or per-function basis
by means of a simple "scope" declaration.
- can access the :ref:`request <request>` object which allows to
introspect and interact with the (scoped) testcontext.
- can add cleanup functions which will be invoked when the last test
of the fixture test context has finished executing.
All of these features are now demonstrated by little examples.
test modules accessing a global resource
-------------------------------------------------------
.. note::
Relying on `global state is considered bad programming practise <http://en.wikipedia.org/wiki/Global_variable>`_ but when you work with an application
that relies on it you often have no choice.
If you want test modules to access a global resource,
you can stick the resource to the module globals in
a per-module autouse function. We use a :ref:`resource factory
<@pytest.fixture>` to create our global resource::
# content of conftest.py
import pytest
class GlobalResource:
def __init__(self):
pass
@pytest.fixture(scope="session")
def globresource():
return GlobalResource()
@pytest.fixture(scope="module")
def setresource(request, globresource):
request.module.globresource = globresource
Now any test module can access ``globresource`` as a module global::
# content of test_glob.py
def test_1():
print ("test_1 %s" % globresource)
def test_2():
print ("test_2 %s" % globresource)
Let's run this module without output-capturing::
$ py.test -qs test_glob.py
FF
================================= FAILURES =================================
__________________________________ test_1 __________________________________
def test_1():
> print ("test_1 %s" % globresource)
E NameError: global name 'globresource' is not defined
test_glob.py:3: NameError
__________________________________ test_2 __________________________________
def test_2():
> print ("test_2 %s" % globresource)
E NameError: global name 'globresource' is not defined
test_glob.py:5: NameError
2 failed in 0.01 seconds
The two tests see the same global ``globresource`` object.
Parametrizing the global resource
+++++++++++++++++++++++++++++++++++++++++++++++++
We extend the previous example and add parametrization to the globresource
factory and also add a finalizer::
# content of conftest.py
import pytest
class GlobalResource:
def __init__(self, param):
self.param = param
@pytest.fixture(scope="session", params=[1,2])
def globresource(request):
g = GlobalResource(request.param)
def fin():
print "finalizing", g
request.addfinalizer(fin)
return g
@pytest.fixture(scope="module")
def setresource(request, globresource):
request.module.globresource = globresource
And then re-run our test module::
$ py.test -qs test_glob.py
FF
================================= FAILURES =================================
__________________________________ test_1 __________________________________
def test_1():
> print ("test_1 %s" % globresource)
E NameError: global name 'globresource' is not defined
test_glob.py:3: NameError
__________________________________ test_2 __________________________________
def test_2():
> print ("test_2 %s" % globresource)
E NameError: global name 'globresource' is not defined
test_glob.py:5: NameError
2 failed in 0.01 seconds
We are now running the two tests twice with two different global resource
instances. Note that the tests are ordered such that only
one instance is active at any given time: the finalizer of
the first globresource instance is called before the second
instance is created and sent to the autouse functions.

View File

@@ -4,7 +4,7 @@
Setting up bash completion
==========================
When using bash as your shell, ``py.test`` can use argcomplete
When using bash as your shell, ``pytest`` can use argcomplete
(https://argcomplete.readthedocs.org/) for auto-completion.
For this ``argcomplete`` needs to be installed **and** enabled.
@@ -16,11 +16,11 @@ For global activation of all argcomplete enabled python applications run::
sudo activate-global-python-argcomplete
For permanent (but not global) ``py.test`` activation, use::
For permanent (but not global) ``pytest`` activation, use::
register-python-argcomplete py.test >> ~/.bashrc
For one-time activation of argcomplete for ``py.test`` only, use::
For one-time activation of argcomplete for ``pytest`` only, use::
eval "$(register-python-argcomplete py.test)"

View File

@@ -80,7 +80,7 @@ You can ask for available builtin or project-custom
capfd
enables capturing of writes to file descriptors 1 and 2 and makes
captured output available via ``capsys.readouterr()`` method calls
captured output available via ``capfd.readouterr()`` method calls
which return a ``(out, err)`` tuple.
monkeypatch

View File

@@ -23,7 +23,7 @@ a test.
Setting capturing methods or disabling capturing
-------------------------------------------------
There are two ways in which ``py.test`` can perform capturing:
There are two ways in which ``pytest`` can perform capturing:
* file descriptor (FD) level capturing (default): All writes going to the
operating system file descriptors 1 and 2 will be captured.
@@ -49,7 +49,7 @@ One primary benefit of the default capturing of stdout/stderr output
is that you can use print statements for debugging::
# content of test_module.py
def setup_function(function):
print ("setting up %s" % function)
@@ -64,7 +64,7 @@ of the failing function and hide the other one::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
test_module.py .F
@@ -77,18 +77,16 @@ of the failing function and hide the other one::
E assert False
test_module.py:9: AssertionError
----------------------------- Captured stdout ------------------------------
setting up <function test_func2 at 0x1eb37d0>
-------------------------- Captured stdout setup ---------------------------
setting up <function test_func2 at 0x2b5d6a81c9d8>
==================== 1 failed, 1 passed in 0.01 seconds ====================
Accessing captured output from a test function
---------------------------------------------------
The :ref:`funcarg mechanism` allows test function a very easy
way to access the captured output by simply using the names
``capsys`` or ``capfd`` in the test function signature. Here
is an example test function that performs some output related
checks::
The ``capsys`` and ``capfd`` fixtures allow to access stdout/stderr
output created during test execution. Here is an example test function
that performs some output related checks::
def test_myoutput(capsys): # or use "capfd" for fd-level
print ("hello")
@@ -105,11 +103,13 @@ and capturing will be continued. After the test
function finishes the original streams will
be restored. Using ``capsys`` this way frees your
test from having to care about setting/resetting
output streams and also interacts well with py.test's
output streams and also interacts well with pytest's
own per-test capturing.
If you want to capture on ``fd`` level you can use
If you want to capture on filedescriptor level you can use
the ``capfd`` function argument which offers the exact
same interface.
same interface but allows to also capture output from
libraries or subprocesses that directly write to operating
system level output streams (FD1 and FD2).
.. include:: links.inc

View File

@@ -17,8 +17,8 @@
#
# The full version, including alpha/beta/rc tags.
# The short X.Y version.
version = "2.5.1"
release = "2.5.1"
version = "2.6"
release = "2.6.2"
import sys, os
@@ -54,7 +54,7 @@ master_doc = 'contents'
# General information about the project.
project = u'pytest'
copyright = u'2012, holger krekel'
copyright = u'2014, holger krekel'
@@ -131,12 +131,12 @@ html_short_title = "pytest-%s" % release
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
html_logo = "img/pytest1.png"
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
html_favicon = "img/pytest1favi.ico"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
@@ -220,12 +220,12 @@ htmlhelp_basename = 'pytestdoc'
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('contents', 'pytest.tex', u'pytest Documentation',
u'holger krekel, http://merlinux.eu', 'manual'),
u'holger krekel, trainer and consultant, http://merlinux.eu', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
latex_logo = 'img/pytest1.png'
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
@@ -262,7 +262,7 @@ man_pages = [
epub_title = u'pytest'
epub_author = u'holger krekel at merlinux eu'
epub_publisher = u'holger krekel at merlinux eu'
epub_copyright = u'2012, holger krekel et alii'
epub_copyright = u'2013, holger krekel et alii'
# The language of the text. It defaults to the language option
# or en if the language is not set.

View File

@@ -18,6 +18,9 @@ Contact channels
- `pytest-commit at python.org (mailing list)`_: for commits and new issues
- :doc:`contribution guide <contributing>` for help on submitting pull
requests to bitbucket (including using git via gitifyhg).
- #pylib on irc.freenode.net IRC channel for random questions.
- private mail to Holger.Krekel at gmail com if you want to communicate sensitive issues

View File

@@ -1,4 +1,10 @@
.. note::
`improving your automated testing with pytest <https://ep2014.europython.eu/en/schedule/sessions/92/>`_, July 25th 2014, Berlin, Germany
`professional testing with pytest and tox <http://www.python-academy.com/courses/specialtopics/python_course_testing.html>`_, 24-26th November 2014, Freiburg, Germany
.. _toc:
Full pytest documentation
@@ -14,9 +20,10 @@ Full pytest documentation
overview
apiref
plugins
plugins_index/index
example/index
talks
develop
contributing
funcarg_compare.txt
announce/index

3
doc/en/contributing.txt Normal file
View File

@@ -0,0 +1,3 @@
.. _contributing:
.. include:: ../../CONTRIBUTING.rst

View File

@@ -17,7 +17,7 @@ which were registered by installed plugins.
How test configuration is read from configuration INI-files
-------------------------------------------------------------
py.test searches for the first matching ini-style configuration file
``pytest`` searches for the first matching ini-style configuration file
in the directories of command line argument and the directories above.
It looks for file basenames in this order::
@@ -26,8 +26,8 @@ It looks for file basenames in this order::
setup.cfg
Searching stops when the first ``[pytest]`` section is found in any of
these files. There is no merging of configuration values from multiple
files. Example::
these files. There is no merging of configuration values from multiple
files. Example::
py.test path/to/testdir
@@ -41,7 +41,7 @@ will look in the following dirs for a config file::
path/to/setup.cfg
... # up until root of filesystem
If argument is provided to a py.test run, the current working directory
If argument is provided to a ``pytest`` run, the current working directory
is used to start the search.
.. _`how to change command line options defaults`:
@@ -51,7 +51,7 @@ How to change command line options defaults
------------------------------------------------
It can be tedious to type the same series of command line options
every time you use py.test . For example, if you always want to see
every time you use ``pytest``. For example, if you always want to see
detailed info on skipped and xfailed tests, as well as have terser "dot"
progress output, you can write it into a configuration file::
@@ -60,7 +60,7 @@ progress output, you can write it into a configuration file::
[pytest]
addopts = -rsxX -q
From now on, running ``py.test`` will add the specified options.
From now on, running ``pytest`` will add the specified options.
Builtin configuration file options
----------------------------------------------
@@ -97,15 +97,15 @@ Builtin configuration file options
[seq] matches any character in seq
[!seq] matches any char not in seq
Default patterns are ``.* _darcs CVS {args}``. Setting a ``norecursedir``
replaces the default. Here is an example of how to avoid
certain directories::
Default patterns are ``'.*', 'CVS', '_darcs', '{arch}', '*.egg'``.
Setting a ``norecursedirs`` replaces the default. Here is an example of
how to avoid certain directories::
# content of setup.cfg
[pytest]
norecursedirs = .svn _build tmp*
This would tell py.test to not look into typical subversion or
This would tell ``pytest`` to not look into typical subversion or
sphinx-build directories or into any ``tmp`` prefixed directory.
.. confval:: python_files
@@ -122,7 +122,7 @@ Builtin configuration file options
One or more name prefixes determining which test functions
and methods are considered as test modules. Note that this
has no effect on methods that live on a ``unittest.TestCase``
has no effect on methods that live on a ``unittest.TestCase``
derived class.
See :ref:`change naming conventions` for examples.

View File

@@ -1,40 +0,0 @@
=================================================
Feedback and contribute to py.test
=================================================
.. toctree::
:maxdepth: 2
contact.txt
.. _checkout:
Working from version control or a tarball
=================================================
To follow development or start experiments, checkout the
complete code and documentation source with mercurial_::
hg clone https://bitbucket.org/hpk42/pytest/
You can also go to the python package index and
download and unpack a TAR file::
http://pypi.python.org/pypi/pytest/
Activating a checkout with setuptools
--------------------------------------------
With a working Distribute_ or setuptools_ installation you can type::
python setup.py develop
in order to work inline with the tools and the lib of your checkout.
If this command complains that it could not find the required version
of "py" then you need to use the development pypi repository::
python setup.py develop -i http://pypi.testrun.org
.. include:: links.inc

View File

@@ -44,12 +44,12 @@ then you can just invoke ``py.test`` without command line options::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 1 items
mymodule.py .
========================= 1 passed in 0.01 seconds =========================
========================= 1 passed in 0.06 seconds =========================
It is possible to use fixtures using the ``getfixture`` helper::

View File

@@ -1,4 +1,4 @@
from py.test import raises
from pytest import raises
import py
def otherfunc(a,b):

View File

@@ -21,6 +21,9 @@ You can "mark" a test function with custom metadata like this::
pass
def test_another():
pass
class TestClass:
def test_method(self):
pass
.. versionadded:: 2.2
@@ -28,26 +31,82 @@ You can then restrict a test run to only run tests marked with ``webtest``::
$ py.test -v -m webtest
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
collecting ... collected 3 items
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 4 items
test_server.py:3: test_send_http PASSED
test_server.py::test_send_http PASSED
=================== 2 tests deselected by "-m 'webtest'" ===================
================== 1 passed, 2 deselected in 0.01 seconds ==================
=================== 3 tests deselected by "-m 'webtest'" ===================
================== 1 passed, 3 deselected in 0.01 seconds ==================
Or the inverse, running all tests except the webtest ones::
$ py.test -v -m "not webtest"
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
collecting ... collected 3 items
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 4 items
test_server.py:6: test_something_quick PASSED
test_server.py:8: test_another PASSED
test_server.py::test_something_quick PASSED
test_server.py::test_another PASSED
test_server.py::TestClass::test_method PASSED
================= 1 tests deselected by "-m 'not webtest'" =================
================== 2 passed, 1 deselected in 0.01 seconds ==================
================== 3 passed, 1 deselected in 0.01 seconds ==================
Selecing tests based on their node ID
-------------------------------------
You can provide one or more :ref:`node IDs <node-id>` as positional
arguments to select only specified tests. This makes it easy to select
tests based on their module, class, method, or function name::
$ py.test -v test_server.py::TestClass::test_method
=========================== test session starts ============================
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 5 items
test_server.py::TestClass::test_method PASSED
========================= 1 passed in 0.01 seconds =========================
You can also select on the class::
$ py.test -v test_server.py::TestClass
=========================== test session starts ============================
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 4 items
test_server.py::TestClass::test_method PASSED
========================= 1 passed in 0.01 seconds =========================
Or select multiple nodes::
$ py.test -v test_server.py::TestClass test_server.py::test_send_http
=========================== test session starts ============================
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 8 items
test_server.py::TestClass::test_method PASSED
test_server.py::test_send_http PASSED
========================= 2 passed in 0.01 seconds =========================
.. _node-id:
.. note::
Node IDs are of the form ``module.py::class::method`` or
``module.py::function``. Node IDs control which tests are
collected, so ``module.py::class`` will select all test methods
on the class. Nodes are also created for each parameter of a
parametrized fixture or test, so selecting a parametrized test
must include the parameter value, e.g.
``module.py::function[param]``.
Node IDs for failing tests are displayed in the test summary info
when running py.test with the ``-rf`` option. You can also
construct Node IDs from the output of ``py.test --collectonly``.
Using ``-k expr`` to select tests based on their name
-------------------------------------------------------
@@ -61,39 +120,40 @@ select tests based on their names::
$ py.test -v -k http # running with the above defined example module
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
collecting ... collected 3 items
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 4 items
test_server.py:3: test_send_http PASSED
test_server.py::test_send_http PASSED
====================== 2 tests deselected by '-khttp' ======================
================== 1 passed, 2 deselected in 0.01 seconds ==================
====================== 3 tests deselected by '-khttp' ======================
================== 1 passed, 3 deselected in 0.01 seconds ==================
And you can also run all tests except the ones that match the keyword::
$ py.test -k "not send_http" -v
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
collecting ... collected 3 items
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 4 items
test_server.py:6: test_something_quick PASSED
test_server.py:8: test_another PASSED
test_server.py::test_something_quick PASSED
test_server.py::test_another PASSED
test_server.py::TestClass::test_method PASSED
================= 1 tests deselected by '-knot send_http' ==================
================== 2 passed, 1 deselected in 0.01 seconds ==================
================== 3 passed, 1 deselected in 0.01 seconds ==================
Or to select "http" and "quick" tests::
$ py.test -k "http or quick" -v
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
collecting ... collected 3 items
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 4 items
test_server.py:3: test_send_http PASSED
test_server.py:6: test_something_quick PASSED
test_server.py::test_send_http PASSED
test_server.py::test_something_quick PASSED
================= 1 tests deselected by '-khttp or quick' ==================
================== 2 passed, 1 deselected in 0.01 seconds ==================
================= 2 tests deselected by '-khttp or quick' ==================
================== 2 passed, 2 deselected in 0.01 seconds ==================
.. note::
@@ -127,7 +187,7 @@ You can ask which markers exist for your test suite - the list includes our just
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in 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. see http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True): mark the the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. See http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None): mark the the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@@ -150,8 +210,8 @@ For an example on how to add and work with markers from a plugin, see
* asking for existing markers via ``py.test --markers`` gives good output
* typos in function markers are treated as an error if you use
the ``--strict`` option. Later versions of py.test are probably
going to treat non-registered markers as an error.
the ``--strict`` option. Future versions of ``pytest`` are probably
going to start treating non-registered markers as errors at some point.
.. _`scoped-marking`:
@@ -266,18 +326,18 @@ the test needs::
$ py.test -E stage2
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 1 items
test_someenv.py s
======================== 1 skipped in 0.01 seconds =========================
and here is one that specifies exactly the environment needed::
$ py.test -E stage1
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 1 items
test_someenv.py .
@@ -291,7 +351,7 @@ The ``--markers`` option always gives you a list of available markers::
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in 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. see http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True): mark the the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. See http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None): mark the the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@@ -301,7 +361,7 @@ The ``--markers`` option always gives you a list of available markers::
@pytest.mark.trylast: mark a hook implementation function such that the plugin machinery will try to call it last/as late as possible.
Reading markers which were set from multiple places
----------------------------------------------------
@@ -337,7 +397,7 @@ test function. From a conftest file we can read it like this::
Let's run this without capturing output and see what we get::
$ py.test -q -s
$ py.test -q -s
glob args=('function',) kwargs={'x': 3}
glob args=('class',) kwargs={'x': 2}
glob args=('module',) kwargs={'x': 1}
@@ -352,7 +412,7 @@ marking platform specific tests with pytest
Consider you have a test suite which marks tests for particular platforms,
namely ``pytest.mark.osx``, ``pytest.mark.win32`` etc. and you
also have tests that run on all platforms and have no specific
marker. If you now want to have a way to only run the tests
marker. If you now want to have a way to only run the tests
for your particular platform, you could use the following plugin::
# content of conftest.py
@@ -395,28 +455,28 @@ then you will see two test skipped and two executed tests as expected::
$ py.test -rs # this option reports skip reasons
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 4 items
test_plat.py s.s.
test_plat.py sss.
========================= short test summary info ==========================
SKIP [2] /tmp/doc-exec-63/conftest.py:12: cannot run on platform linux2
SKIP [3] /tmp/doc-exec-238/conftest.py:12: cannot run on platform linux
=================== 2 passed, 2 skipped in 0.01 seconds ====================
=================== 1 passed, 3 skipped in 0.01 seconds ====================
Note that if you specify a platform via the marker-command line option like this::
$ py.test -m linux2
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 4 items
test_plat.py .
test_plat.py s
=================== 3 tests deselected by "-m 'linux2'" ====================
================== 1 passed, 3 deselected in 0.01 seconds ==================
================= 1 skipped, 3 deselected in 0.01 seconds ==================
then the unmarked-tests will not be run. It is thus a way to restrict the run to the specific tests.
then the unmarked-tests will not be run. It is thus a way to restrict the run to the specific tests.
Automatically adding markers based on test names
--------------------------------------------------------
@@ -435,7 +495,7 @@ at this test module::
def test_interface_complex():
assert 0
def test_event_simple():
assert 0
@@ -446,7 +506,7 @@ We want to dynamically define two markers and can do it in a
``conftest.py`` plugin::
# content of conftest.py
import pytest
def pytest_collection_modifyitems(items):
for item in items:
@@ -459,7 +519,7 @@ We can now use the ``-m option`` to select one set::
$ py.test -m interface --tb=short
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 4 items
test_module.py FF
@@ -467,12 +527,12 @@ We can now use the ``-m option`` to select one set::
================================= FAILURES =================================
__________________________ test_interface_simple ___________________________
test_module.py:3: in test_interface_simple
> assert 0
E assert 0
assert 0
E assert 0
__________________________ test_interface_complex __________________________
test_module.py:6: in test_interface_complex
> assert 0
E assert 0
assert 0
E assert 0
================== 2 tests deselected by "-m 'interface'" ==================
================== 2 failed, 2 deselected in 0.01 seconds ==================
@@ -480,7 +540,7 @@ or to select both "event" and "interface" tests::
$ py.test -m "interface or event" --tb=short
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 4 items
test_module.py FFF
@@ -488,15 +548,15 @@ or to select both "event" and "interface" tests::
================================= FAILURES =================================
__________________________ test_interface_simple ___________________________
test_module.py:3: in test_interface_simple
> assert 0
E assert 0
assert 0
E assert 0
__________________________ test_interface_complex __________________________
test_module.py:6: in test_interface_complex
> assert 0
E assert 0
assert 0
E assert 0
____________________________ test_event_simple _____________________________
test_module.py:9: in test_event_simple
> assert 0
E assert 0
assert 0
E assert 0
============= 1 tests deselected by "-m 'interface or event'" ==============
================== 3 failed, 1 deselected in 0.01 seconds ==================

View File

@@ -2,9 +2,10 @@
module containing a parametrized tests testing cross-python
serialization via the pickle module.
"""
import py, pytest
import py
import pytest
pythonlist = ['python2.4', 'python2.5', 'python2.6', 'python2.7', 'python2.8']
pythonlist = ['python2.6', 'python2.7', 'python3.4']
@pytest.fixture(params=pythonlist)
def python1(request, tmpdir):
picklefile = tmpdir.join("data.pickle")
@@ -18,7 +19,7 @@ class Python:
def __init__(self, version, picklefile):
self.pythonpath = py.path.local.sysfind(version)
if not self.pythonpath:
py.test.skip("%r not found" %(version,))
pytest.skip("%r not found" %(version,))
self.picklefile = picklefile
def dumps(self, obj):
dumpfile = self.picklefile.dirpath("dump.py")

View File

@@ -27,7 +27,7 @@ now execute the test specification::
nonpython $ py.test test_simple.yml
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
test_simple.yml .F
@@ -56,11 +56,11 @@ consulted when reporting in ``verbose`` mode::
nonpython $ py.test -v
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 2 items
test_simple.yml:1: usecase: ok PASSED
test_simple.yml:1: usecase: hello FAILED
test_simple.yml::usecase: ok PASSED
test_simple.yml::usecase: hello FAILED
================================= FAILURES =================================
______________________________ usecase: hello ______________________________
@@ -74,10 +74,10 @@ interesting to just look at the collection tree::
nonpython $ py.test --collect-only
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
<YamlFile 'test_simple.yml'>
<YamlItem 'ok'>
<YamlItem 'hello'>
============================= in 0.02 seconds =============================
============================= in 0.03 seconds =============================

View File

@@ -6,7 +6,7 @@ Parametrizing tests
.. currentmodule:: _pytest.python
py.test allows to easily parametrize test functions.
``pytest`` allows to easily parametrize test functions.
For basic docs, see :ref:`parametrize-basics`.
In the following we provide some examples using
@@ -55,13 +55,13 @@ let's run the full monty::
....F
================================= FAILURES =================================
_____________________________ test_compute[4] ______________________________
param1 = 4
def test_compute(param1):
> assert param1 < 4
E assert 4 < 4
test_compute.py:3: AssertionError
1 failed, 4 passed in 0.01 seconds
@@ -106,7 +106,7 @@ this is a fully self-contained example which you can run with::
$ py.test test_scenarios.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 4 items
test_scenarios.py ....
@@ -118,7 +118,7 @@ If you just collect tests you'll also nicely see 'advanced' and 'basic' as varia
$ py.test --collect-only test_scenarios.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 4 items
<Module 'test_scenarios.py'>
<Class 'TestSampleWithScenarios'>
@@ -182,7 +182,7 @@ Let's first see how it looks like at collection time::
$ py.test test_backends.py --collect-only
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
<Module 'test_backends.py'>
<Function 'test_db_initialized[d1]'>
@@ -197,7 +197,7 @@ And then when we run the test::
================================= FAILURES =================================
_________________________ test_db_initialized[d2] __________________________
db = <conftest.DB2 instance at 0x12d4128>
db = <conftest.DB2 object at 0x2b83684b5eb8>
def test_db_initialized(db):
# a dummy test
@@ -253,7 +253,7 @@ argument sets to use for each test function. Let's run it::
================================= FAILURES =================================
________________________ TestClass.test_equals[2-1] ________________________
self = <test_parametrize.TestClass instance at 0x14493f8>, a = 1, b = 2
self = <test_parametrize.TestClass object at 0x2ae94130e390>, a = 1, b = 2
def test_equals(self, a, b):
> assert a == b
@@ -279,10 +279,12 @@ is to be run with different sets of arguments for its three arguments:
Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize)::
. $ py.test -rs -q multipython.py
............sss............sss............sss............ssssssssssssssssss
ssssssssssssssssssssssssssssssssssss......sssssssss......ssssssssssssssssss
========================= short test summary info ==========================
SKIP [27] /home/hpk/p/pytest/doc/en/example/multipython.py:21: 'python2.8' not found
48 passed, 27 skipped in 1.34 seconds
SKIP [21] /home/hpk/p/pytest/doc/en/example/multipython.py:22: 'python2.5' not found
SKIP [21] /home/hpk/p/pytest/doc/en/example/multipython.py:22: 'python2.8' not found
SKIP [21] /home/hpk/p/pytest/doc/en/example/multipython.py:22: 'python2.4' not found
12 passed, 63 skipped in 0.65 seconds
Indirect parametrization of optional implementations/imports
--------------------------------------------------------------------
@@ -290,7 +292,7 @@ Indirect parametrization of optional implementations/imports
If you want to compare the outcomes of several implementations of a given
API, you can write test functions that receive the already imported implementations
and get skipped in case the implementation is not importable/available. Let's
say we have a "base" implementation and the other (possibly optimized ones)
say we have a "base" implementation and the other (possibly optimized ones)
need to provide similar results::
# content of conftest.py
@@ -329,12 +331,12 @@ If you run this with reporting for skips enabled::
$ py.test -rs test_module.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
test_module.py .s
========================= short test summary info ==========================
SKIP [1] /tmp/doc-exec-65/conftest.py:10: could not import 'opt2'
SKIP [1] /tmp/doc-exec-240/conftest.py:10: could not import 'opt2'
=================== 1 passed, 1 skipped in 0.01 seconds ====================
@@ -342,13 +344,13 @@ You'll see that we don't have a ``opt2`` module and thus the second test run
of our ``test_func1`` was skipped. A few notes:
- the fixture functions in the ``conftest.py`` file are "session-scoped" because we
don't need to import more than once
don't need to import more than once
- if you have multiple test functions and a skipped import, you will see
the ``[1]`` count increasing in the report
- you can put :ref:`@pytest.mark.parametrize <@pytest.mark.parametrize>` style
parametrization on the test functions to parametrize input/output
parametrization on the test functions to parametrize input/output
values as well.

View File

@@ -10,7 +10,7 @@ You can set the :confval:`norecursedirs` option in an ini-file, for example your
[pytest]
norecursedirs = .svn _build tmp*
This would tell py.test to not recurse into typical subversion or sphinx-build directories or into any ``tmp`` prefixed directory.
This would tell ``pytest`` to not recurse into typical subversion or sphinx-build directories or into any ``tmp`` prefixed directory.
.. _`change naming conventions`:
@@ -28,7 +28,7 @@ the :confval:`python_files`, :confval:`python_classes` and
python_classes=Check
python_functions=check
This would make py.test look for ``check_`` prefixes in
This would make ``pytest`` look for ``check_`` prefixes in
Python filenames, ``Check`` prefixes in classes and ``check`` prefixes
in functions and classes. For example, if we have::
@@ -43,7 +43,7 @@ then the test collection looks like this::
$ py.test --collect-only
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
<Module 'check_myapp.py'>
<Class 'CheckMyApp'>
@@ -54,7 +54,7 @@ then the test collection looks like this::
============================= in 0.01 seconds =============================
.. note::
the ``python_functions`` and ``python_classes`` has no effect
for ``unittest.TestCase`` test discovery because pytest delegates
detection of test case methods to unittest code.
@@ -62,7 +62,7 @@ then the test collection looks like this::
Interpreting cmdline arguments as Python packages
-----------------------------------------------------
You can use the ``--pyargs`` option to make py.test try
You can use the ``--pyargs`` option to make ``pytest`` try
interpreting arguments as python package names, deriving
their file system path and then running the test. For
example if you have unittest2 installed you can type::
@@ -88,7 +88,7 @@ You can always peek at the collection tree without running tests like this::
. $ py.test --collect-only pythoncollection.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 3 items
<Module 'pythoncollection.py'>
<Function 'test_function'>
@@ -104,7 +104,7 @@ customizing test collection to find all .py files
.. regendoc:wipe
You can easily instruct py.test to discover tests from every python file::
You can easily instruct ``pytest`` to discover tests from every python file::
# content of pytest.ini
@@ -112,8 +112,8 @@ You can easily instruct py.test to discover tests from every python file::
python_files = *.py
However, many projects will have a ``setup.py`` which they don't want to be imported. Moreover, there may files only importable by a specific python version.
For such cases you can dynamically define files to be ignored by listing
them in a ``conftest.py`` file::
For such cases you can dynamically define files to be ignored by listing
them in a ``conftest.py`` file::
# content of conftest.py
import sys
@@ -136,15 +136,13 @@ and a setup.py dummy file like this::
# content of setup.py
0/0 # will raise exeption if imported
then a pytest run on python2 will find the one test when run with a python2
then a pytest run on python2 will find the one test when run with a python2
interpreters and will leave out the setup.py file::
$ py.test --collect-only
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
collected 1 items
<Module 'pkg/module_py2.py'>
<Function 'test_only_on_python2'>
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 0 items
============================= in 0.01 seconds =============================

View File

@@ -1,11 +1,11 @@
.. _`tbreportdemo`:
Demo of Python failure reports with py.test
Demo of Python failure reports with pytest
==================================================
Here is a nice run of several tens of failures
and how py.test presents things (unfortunately
and how ``pytest`` presents things (unfortunately
not showing the nice colors here in the HTML that you
get on the terminal - we are working on that):
@@ -13,7 +13,7 @@ get on the terminal - we are working on that):
assertion $ py.test failure_demo.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 39 items
failure_demo.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@@ -30,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 0x12d9250>
self = <failure_demo.TestFailing object at 0x2aec3e52d470>
def test_simple(self):
def f():
@@ -40,13 +40,13 @@ get on the terminal - we are working on that):
> assert f() == g()
E assert 42 == 43
E + where 42 = <function f at 0x1278b90>()
E + and 43 = <function g at 0x1278c08>()
E + where 42 = <function TestFailing.test_simple.<locals>.f at 0x2aec3e47b158>()
E + and 43 = <function TestFailing.test_simple.<locals>.g at 0x2aec3e47b268>()
failure_demo.py:28: AssertionError
____________________ TestFailing.test_simple_multiline _____________________
self = <failure_demo.TestFailing object at 0x1287210>
self = <failure_demo.TestFailing object at 0x2aec3e474ac8>
def test_simple_multiline(self):
otherfunc_multi(
@@ -66,19 +66,19 @@ get on the terminal - we are working on that):
failure_demo.py:11: AssertionError
___________________________ TestFailing.test_not ___________________________
self = <failure_demo.TestFailing object at 0x12c6e10>
self = <failure_demo.TestFailing object at 0x2aec3e5156a0>
def test_not(self):
def f():
return 42
> assert not f()
E assert not 42
E + where 42 = <function f at 0x12861b8>()
E + where 42 = <function TestFailing.test_not.<locals>.f at 0x2aec3e47e620>()
failure_demo.py:38: AssertionError
_________________ TestSpecialisedExplanations.test_eq_text _________________
self = <failure_demo.TestSpecialisedExplanations object at 0x1290c50>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e50cba8>
def test_eq_text(self):
> assert 'spam' == 'eggs'
@@ -89,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 0x12877d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e4e24e0>
def test_eq_similar_text(self):
> assert 'foo 1 bar' == 'foo 2 bar'
@@ -102,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 0x12de1d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e4cc6d8>
def test_eq_multiline_text(self):
> assert 'foo\nspam\nbar' == 'foo\neggs\nbar'
@@ -115,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 0x143b5d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e501908>
def test_eq_long_text(self):
a = '1'*100 + 'a' + '2'*100
@@ -132,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 0x1287810>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e3af048>
def test_eq_long_text_multiline(self):
a = '1\n'*100 + 'a' + '2\n'*100
@@ -156,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 0x12900d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e474c50>
def test_eq_list(self):
> assert [0, 1, 2] == [0, 1, 3]
@@ -166,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 0x12c62d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e515dd8>
def test_eq_list_long(self):
a = [0]*100 + [1] + [3]*100
@@ -178,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 0x12deb50>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e4a5ef0>
def test_eq_dict(self):
> assert {'a': 0, 'b': 1, 'c': 0} == {'a': 0, 'b': 2, 'd': 0}
@@ -194,7 +194,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 0x128b4d0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e4a2e48>
def test_eq_set(self):
> assert set([0, 10, 11, 12]) == set([0, 20, 21])
@@ -210,7 +210,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 0x12c6b10>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e4e0c50>
def test_eq_longer_list(self):
> assert [1,2] == [1,2,3]
@@ -220,7 +220,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 0x143b650>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e4950f0>
def test_in_list(self):
> assert 1 in [0, 2, 3, 4, 5]
@@ -229,7 +229,7 @@ get on the terminal - we are working on that):
failure_demo.py:78: AssertionError
__________ TestSpecialisedExplanations.test_not_in_text_multiline __________
self = <failure_demo.TestSpecialisedExplanations object at 0x128be10>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e474f98>
def test_not_in_text_multiline(self):
text = 'some multiline\ntext\nwhich\nincludes foo\nand a\ntail'
@@ -247,7 +247,7 @@ get on the terminal - we are working on that):
failure_demo.py:82: AssertionError
___________ TestSpecialisedExplanations.test_not_in_text_single ____________
self = <failure_demo.TestSpecialisedExplanations object at 0x12d9fd0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e5333c8>
def test_not_in_text_single(self):
text = 'single foo line'
@@ -260,7 +260,7 @@ get on the terminal - we are working on that):
failure_demo.py:86: AssertionError
_________ TestSpecialisedExplanations.test_not_in_text_single_long _________
self = <failure_demo.TestSpecialisedExplanations object at 0x143bdd0>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e4ccb70>
def test_not_in_text_single_long(self):
text = 'head ' * 50 + 'foo ' + 'tail ' * 20
@@ -273,7 +273,7 @@ get on the terminal - we are working on that):
failure_demo.py:90: AssertionError
______ TestSpecialisedExplanations.test_not_in_text_single_long_term _______
self = <failure_demo.TestSpecialisedExplanations object at 0x12c6390>
self = <failure_demo.TestSpecialisedExplanations object at 0x2aec3e502080>
def test_not_in_text_single_long_term(self):
text = 'head ' * 50 + 'f'*70 + 'tail ' * 20
@@ -292,7 +292,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 0x1287790>.b
E + where 1 = <failure_demo.test_attribute.<locals>.Foo object at 0x2aec3e519c18>.b
failure_demo.py:101: AssertionError
_________________________ test_attribute_instance __________________________
@@ -302,8 +302,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 0x12c6bd0>.b
E + where <failure_demo.Foo object at 0x12c6bd0> = <class 'failure_demo.Foo'>()
E + where 1 = <failure_demo.test_attribute_instance.<locals>.Foo object at 0x2aec3e52d898>.b
E + where <failure_demo.test_attribute_instance.<locals>.Foo object at 0x2aec3e52d898> = <class 'failure_demo.test_attribute_instance.<locals>.Foo'>()
failure_demo.py:107: AssertionError
__________________________ test_attribute_failure __________________________
@@ -319,7 +319,7 @@ get on the terminal - we are working on that):
failure_demo.py:116:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <failure_demo.Foo object at 0x12daed0>
self = <failure_demo.test_attribute_failure.<locals>.Foo object at 0x2aec3e4e0b38>
def _get_b(self):
> raise Exception('Failed to get attrib')
@@ -335,15 +335,15 @@ 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 0x128bcd0>.b
E + where <failure_demo.Foo object at 0x128bcd0> = <class 'failure_demo.Foo'>()
E + and 2 = <failure_demo.Bar object at 0x128b050>.b
E + where <failure_demo.Bar object at 0x128b050> = <class 'failure_demo.Bar'>()
E + where 1 = <failure_demo.test_attribute_multiple.<locals>.Foo object at 0x2aec3e4a5748>.b
E + where <failure_demo.test_attribute_multiple.<locals>.Foo object at 0x2aec3e4a5748> = <class 'failure_demo.test_attribute_multiple.<locals>.Foo'>()
E + and 2 = <failure_demo.test_attribute_multiple.<locals>.Bar object at 0x2aec3e4a51d0>.b
E + where <failure_demo.test_attribute_multiple.<locals>.Bar object at 0x2aec3e4a51d0> = <class 'failure_demo.test_attribute_multiple.<locals>.Bar'>()
failure_demo.py:124: AssertionError
__________________________ TestRaises.test_raises __________________________
self = <failure_demo.TestRaises instance at 0x145c7e8>
self = <failure_demo.TestRaises object at 0x2aec3e4a2d68>
def test_raises(self):
s = 'qwe'
@@ -355,10 +355,10 @@ get on the terminal - we are working on that):
> int(s)
E ValueError: invalid literal for int() with base 10: 'qwe'
<0-codegen /home/hpk/p/pytest/.tox/regen/local/lib/python2.7/site-packages/_pytest/python.py:983>:1: ValueError
<0-codegen /home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/python.py:1028>:1: ValueError
______________________ TestRaises.test_raises_doesnt _______________________
self = <failure_demo.TestRaises instance at 0x1455f38>
self = <failure_demo.TestRaises object at 0x2aec3e4e2198>
def test_raises_doesnt(self):
> raises(IOError, "int('3')")
@@ -367,7 +367,7 @@ get on the terminal - we are working on that):
failure_demo.py:136: Failed
__________________________ TestRaises.test_raise ___________________________
self = <failure_demo.TestRaises instance at 0x1453998>
self = <failure_demo.TestRaises object at 0x2aec3e5017b8>
def test_raise(self):
> raise ValueError("demo error")
@@ -376,7 +376,7 @@ get on the terminal - we are working on that):
failure_demo.py:139: ValueError
________________________ TestRaises.test_tupleerror ________________________
self = <failure_demo.TestRaises instance at 0x1465560>
self = <failure_demo.TestRaises object at 0x2aec3e533160>
def test_tupleerror(self):
> a,b = [1]
@@ -385,7 +385,7 @@ get on the terminal - we are working on that):
failure_demo.py:142: ValueError
______ TestRaises.test_reinterpret_fails_with_print_for_the_fun_of_it ______
self = <failure_demo.TestRaises instance at 0x1465758>
self = <failure_demo.TestRaises object at 0x2aec3e4cc438>
def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
l = [1,2,3]
@@ -394,15 +394,15 @@ get on the terminal - we are working on that):
E TypeError: 'int' object is not iterable
failure_demo.py:147: TypeError
----------------------------- Captured stdout ------------------------------
--------------------------- Captured stdout call ---------------------------
l is [1, 2, 3]
________________________ TestRaises.test_some_error ________________________
self = <failure_demo.TestRaises instance at 0x1468ab8>
self = <failure_demo.TestRaises object at 0x2aec3e5199e8>
def test_some_error(self):
> if namenotexi:
E NameError: global name 'namenotexi' is not defined
E NameError: name 'namenotexi' is not defined
failure_demo.py:150: NameError
____________________ test_dynamic_compile_shows_nicely _____________________
@@ -426,7 +426,7 @@ get on the terminal - we are working on that):
<2-codegen 'abc-123' /home/hpk/p/pytest/doc/en/example/assertion/failure_demo.py:162>:2: AssertionError
____________________ TestMoreErrors.test_complex_error _____________________
self = <failure_demo.TestMoreErrors instance at 0x1442908>
self = <failure_demo.TestMoreErrors object at 0x2aec3e515cf8>
def test_complex_error(self):
def f():
@@ -437,13 +437,8 @@ get on the terminal - we are working on that):
failure_demo.py:175:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x = 44, y = 43
def somefunc(x,y):
> otherfunc(x,y)
failure_demo.py:8:
failure_demo.py:8: in somefunc
otherfunc(x,y)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a = 44, b = 43
@@ -455,7 +450,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 0x145bab8>
self = <failure_demo.TestMoreErrors object at 0x2aec3e4f7a58>
def test_z1_unpack_error(self):
l = []
@@ -465,7 +460,7 @@ get on the terminal - we are working on that):
failure_demo.py:179: ValueError
____________________ TestMoreErrors.test_z2_type_error _____________________
self = <failure_demo.TestMoreErrors instance at 0x1444368>
self = <failure_demo.TestMoreErrors object at 0x2aec3e52db38>
def test_z2_type_error(self):
l = 3
@@ -475,19 +470,19 @@ get on the terminal - we are working on that):
failure_demo.py:183: TypeError
______________________ TestMoreErrors.test_startswith ______________________
self = <failure_demo.TestMoreErrors instance at 0x146e4d0>
self = <failure_demo.TestMoreErrors object at 0x2aec3e538a58>
def test_startswith(self):
s = "123"
g = "456"
> assert s.startswith(g)
E assert <built-in method startswith of str object at 0x12dfa58>('456')
E + where <built-in method startswith of str object at 0x12dfa58> = '123'.startswith
E assert <built-in method startswith of str object at 0x2aec3e501420>('456')
E + where <built-in method startswith of str object at 0x2aec3e501420> = '123'.startswith
failure_demo.py:188: AssertionError
__________________ TestMoreErrors.test_startswith_nested ___________________
self = <failure_demo.TestMoreErrors instance at 0x143ed40>
self = <failure_demo.TestMoreErrors object at 0x2aec3e4f1b00>
def test_startswith_nested(self):
def f():
@@ -495,15 +490,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 0x12dfa58>('456')
E + where <built-in method startswith of str object at 0x12dfa58> = '123'.startswith
E + where '123' = <function f at 0x1286500>()
E + and '456' = <function g at 0x126db18>()
E assert <built-in method startswith of str object at 0x2aec3e501420>('456')
E + where <built-in method startswith of str object at 0x2aec3e501420> = '123'.startswith
E + where '123' = <function TestMoreErrors.test_startswith_nested.<locals>.f at 0x2aec3e5572f0>()
E + and '456' = <function TestMoreErrors.test_startswith_nested.<locals>.g at 0x2aec3e557268>()
failure_demo.py:195: AssertionError
_____________________ TestMoreErrors.test_global_func ______________________
self = <failure_demo.TestMoreErrors instance at 0x1453b90>
self = <failure_demo.TestMoreErrors object at 0x2aec3e495438>
def test_global_func(self):
> assert isinstance(globf(42), float)
@@ -513,18 +508,18 @@ get on the terminal - we are working on that):
failure_demo.py:198: AssertionError
_______________________ TestMoreErrors.test_instance _______________________
self = <failure_demo.TestMoreErrors instance at 0x146b128>
self = <failure_demo.TestMoreErrors object at 0x2aec3e567240>
def test_instance(self):
self.x = 6*7
> assert self.x != 42
E assert 42 != 42
E + where 42 = <failure_demo.TestMoreErrors instance at 0x146b128>.x
E + where 42 = <failure_demo.TestMoreErrors object at 0x2aec3e567240>.x
failure_demo.py:202: AssertionError
_______________________ TestMoreErrors.test_compare ________________________
self = <failure_demo.TestMoreErrors instance at 0x1469368>
self = <failure_demo.TestMoreErrors object at 0x2aec3e502cc0>
def test_compare(self):
> assert globf(10) < 5
@@ -534,7 +529,7 @@ get on the terminal - we are working on that):
failure_demo.py:205: AssertionError
_____________________ TestMoreErrors.test_try_finally ______________________
self = <failure_demo.TestMoreErrors instance at 0x12c4098>
self = <failure_demo.TestMoreErrors object at 0x2aec3e5197f0>
def test_try_finally(self):
x = 1
@@ -543,4 +538,4 @@ get on the terminal - we are working on that):
E assert 1 == 0
failure_demo.py:210: AssertionError
======================== 39 failed in 0.20 seconds =========================
======================== 39 failed in 0.22 seconds =========================

View File

@@ -53,7 +53,7 @@ Let's run this without supplying our new option::
E assert 0
test_sample.py:6: AssertionError
----------------------------- Captured stdout ------------------------------
--------------------------- Captured stdout call ---------------------------
first
1 failed in 0.01 seconds
@@ -75,7 +75,7 @@ And now with supplying a command line option::
E assert 0
test_sample.py:6: AssertionError
----------------------------- Captured stdout ------------------------------
--------------------------- Captured stdout call ---------------------------
second
1 failed in 0.01 seconds
@@ -108,7 +108,7 @@ directory with the above conftest.py::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 0 items
============================= in 0.00 seconds =============================
@@ -152,12 +152,12 @@ and when running it will see a skipped "slow" test::
$ py.test -rs # "-rs" means report details on the little 's'
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
test_module.py .s
========================= short test summary info ==========================
SKIP [1] /tmp/doc-exec-68/conftest.py:9: need --runslow option to run
SKIP [1] /tmp/doc-exec-243/conftest.py:9: need --runslow option to run
=================== 1 passed, 1 skipped in 0.01 seconds ====================
@@ -165,7 +165,7 @@ Or run it including the ``slow`` marked test::
$ py.test --runslow
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
test_module.py ..
@@ -193,7 +193,7 @@ Example::
def test_something():
checkconfig(42)
The ``__tracebackhide__`` setting influences py.test showing
The ``__tracebackhide__`` setting influences ``pytest`` showing
of tracebacks: the ``checkconfig`` function will not be shown
unless the ``--fulltrace`` command line option is specified.
Let's run our little function::
@@ -202,15 +202,15 @@ 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.01 seconds
Detect if running from within a py.test run
Detect if running from within a pytest run
--------------------------------------------------------------
.. regendoc:wipe
@@ -245,10 +245,10 @@ Adding info to test report header
.. regendoc:wipe
It's easy to present extra information in a py.test run::
It's easy to present extra information in a ``pytest`` run::
# content of conftest.py
def pytest_report_header(config):
return "project deps: mylib-1.1"
@@ -256,7 +256,7 @@ which will add the string to the test header accordingly::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
project deps: mylib-1.1
collected 0 items
@@ -279,7 +279,7 @@ which will add info only when run with "--v"::
$ py.test -v
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
info1: did you know that ...
did you?
collecting ... collected 0 items
@@ -290,7 +290,7 @@ and nothing when run plainly::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 0 items
============================= in 0.00 seconds =============================
@@ -322,7 +322,7 @@ Now we can profile which test functions execute the slowest::
$ py.test --durations=3
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 3 items
test_some_are_slow.py ...
@@ -330,7 +330,7 @@ Now we can profile which test functions execute the slowest::
========================= slowest 3 test durations =========================
0.20s call test_some_are_slow.py::test_funcslow2
0.10s call test_some_are_slow.py::test_funcslow1
0.00s setup test_some_are_slow.py::test_funcfast
0.00s setup test_some_are_slow.py::test_funcslow2
========================= 3 passed in 0.31 seconds =========================
incremental testing - test steps
@@ -383,7 +383,7 @@ If we run this::
$ py.test -rx
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 4 items
test_step.py .Fx.
@@ -391,7 +391,7 @@ If we run this::
================================= FAILURES =================================
____________________ TestUserHandling.test_modification ____________________
self = <test_step.TestUserHandling instance at 0x2758c20>
self = <test_step.TestUserHandling object at 0x2b2ef2a4feb8>
def test_modification(self):
> assert 0
@@ -448,12 +448,12 @@ the ``db`` fixture::
# content of b/test_error.py
def test_root(db): # no db here, will error out
pass
We can run this::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 7 items
test_step.py .Fx.
@@ -463,17 +463,17 @@ We can run this::
================================== ERRORS ==================================
_______________________ ERROR at setup of test_root ________________________
file /tmp/doc-exec-68/b/test_error.py, line 1
file /tmp/doc-exec-243/b/test_error.py, line 1
def test_root(db): # no db here, will error out
fixture 'db' not found
available fixtures: recwarn, capfd, pytestconfig, capsys, tmpdir, monkeypatch
available fixtures: tmpdir, monkeypatch, capsys, capfd, pytestconfig, recwarn
use 'py.test --fixtures [testpath]' for help on them.
/tmp/doc-exec-68/b/test_error.py:1
/tmp/doc-exec-243/b/test_error.py:1
================================= FAILURES =================================
____________________ TestUserHandling.test_modification ____________________
self = <test_step.TestUserHandling instance at 0x131fc20>
self = <test_step.TestUserHandling object at 0x2b63a7aec710>
def test_modification(self):
> assert 0
@@ -482,20 +482,20 @@ We can run this::
test_step.py:9: AssertionError
_________________________________ test_a1 __________________________________
db = <conftest.DB instance at 0x1328878>
db = <conftest.DB object at 0x2b63a7b04470>
def test_a1(db):
> assert 0, db # to show value
E AssertionError: <conftest.DB instance at 0x1328878>
E AssertionError: <conftest.DB object at 0x2b63a7b04470>
a/test_db.py:2: AssertionError
_________________________________ test_a2 __________________________________
db = <conftest.DB instance at 0x1328878>
db = <conftest.DB object at 0x2b63a7b04470>
def test_a2(db):
> assert 0, db # to show value
E AssertionError: <conftest.DB instance at 0x1328878>
E AssertionError: <conftest.DB object at 0x2b63a7b04470>
a/test_db2.py:2: AssertionError
========== 3 failed, 2 passed, 1 xfailed, 1 error in 0.03 seconds ==========
@@ -512,7 +512,7 @@ post-process test reports / failures
---------------------------------------
If you want to postprocess test reports and need access to the executing
environment you can implement a hook that gets called when the test
environment you can implement a hook that gets called when the test
"report" object is about to be created. Here we write out all failing
test calls and also access a fixture (if it was used by the test) in
case you want to query/look at it during your post processing. In our
@@ -529,7 +529,7 @@ case we just write some informations out to a ``failures`` file::
rep = __multicall__.execute()
# we only look at actual failing test calls, not setup/teardown
if rep.when == "call" and rep.failed:
if rep.when == "call" and rep.failed:
mode = "a" if os.path.exists("failures") else "w"
with open("failures", mode) as f:
# let's also access a fixture for the fun of it
@@ -537,7 +537,7 @@ case we just write some informations out to a ``failures`` file::
extra = " (%s)" % item.funcargs["tmpdir"]
else:
extra = ""
f.write(rep.nodeid + extra + "\n")
return rep
@@ -545,15 +545,15 @@ if you then have failing tests::
# content of test_module.py
def test_fail1(tmpdir):
assert 0
assert 0
def test_fail2():
assert 0
assert 0
and run them::
$ py.test test_module.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 2 items
test_module.py FF
@@ -561,7 +561,7 @@ and run them::
================================= FAILURES =================================
________________________________ test_fail1 ________________________________
tmpdir = local('/tmp/pytest-42/test_fail10')
tmpdir = local('/tmp/pytest-509/test_fail10')
def test_fail1(tmpdir):
> assert 0
@@ -575,12 +575,12 @@ and run them::
E assert 0
test_module.py:4: AssertionError
========================= 2 failed in 0.01 seconds =========================
========================= 2 failed in 0.02 seconds =========================
you will have a "failures" file which contains the failing test ids::
$ cat failures
test_module.py::test_fail1 (/tmp/pytest-42/test_fail10)
test_module.py::test_fail1 (/tmp/pytest-509/test_fail10)
test_module.py::test_fail2
Making test result information available in fixtures
@@ -623,61 +623,99 @@ here is a little example implemented via a local plugin::
if you then have failing tests::
# content of test_module.py
import pytest
@pytest.fixture
def other():
assert 0
def test_setup_fails(something, other):
pass
def test_call_fails(something):
assert 0
assert 0
def test_fail2():
assert 0
assert 0
and run it::
$ py.test -s test_module.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
collected 3 items
Traceback (most recent call last):
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/config.py", line 513, in getconftestmodules
return self._path2confmods[path]
KeyError: local('/tmp/doc-exec-243/test_module.py')
test_module.py Esetting up a test failed! test_module.py::test_setup_fails
Fexecuting test failed test_module.py::test_call_fails
F
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/config.py", line 537, in importconftest
return self._conftestpath2mod[conftestpath]
KeyError: local('/tmp/doc-exec-243/conftest.py')
================================== ERRORS ==================================
____________________ ERROR at setup of test_setup_fails ____________________
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/config.py", line 543, in importconftest
mod = conftestpath.pyimport()
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/py/_path/local.py", line 620, in pyimport
__import__(modname)
File "/tmp/doc-exec-243/conftest.py", line 22
print "setting up a test failed!", request.node.nodeid
^
SyntaxError: invalid syntax
ERROR: could not load /tmp/doc-exec-243/conftest.py
@pytest.fixture
def other():
> assert 0
E assert 0
test_module.py:6: AssertionError
================================= FAILURES =================================
_____________________________ test_call_fails ______________________________
something = None
def test_call_fails(something):
> assert 0
E assert 0
test_module.py:12: AssertionError
________________________________ test_fail2 ________________________________
def test_fail2():
> assert 0
E assert 0
test_module.py:15: AssertionError
==================== 2 failed, 1 error in 0.01 seconds =====================
You'll see that the fixture finalizers could use the precise reporting
information.
Integrating pytest runner and cx_freeze
-----------------------------------------------------------
If you freeze your application using a tool like
`cx_freeze <http://cx-freeze.readthedocs.org>`_ in order to distribute it
to your end-users, it is a good idea to also package your test runner and run
your tests using the frozen application.
This way packaging errors such as dependencies not being
included into the executable can be detected early while also allowing you to
send test files to users so they can run them in their machines, which can be
invaluable to obtain more information about a hard to reproduce bug.
Unfortunately ``cx_freeze`` can't discover them
automatically because of ``pytest``'s use of dynamic module loading, so you
must declare them explicitly by using ``pytest.freeze_includes()``::
# contents of setup.py
from cx_Freeze import setup, Executable
import pytest
setup(
name="app_main",
executables=[Executable("app_main.py")],
options={"build_exe":
{
'includes': pytest.freeze_includes()}
},
# ... other options
)
If you don't want to ship a different executable just in order to run your tests,
you can make your program check for a certain flag and pass control
over to ``pytest`` instead. For example::
# contents of app_main.py
import sys
if len(sys.argv) > 1 and sys.argv[1] == '--pytest':
import pytest
sys.exit(pytest.main(sys.argv[2:]))
else:
# normal application execution: at this point argv can be parsed
# by your argument-parsing library of choice as usual
...
This makes it convenient to execute your tests from within your frozen
application, using standard ``py.test`` command-line options::
$ ./app_main --pytest --verbose --tb=long --junit-xml=results.xml test-suite/

View File

@@ -1,5 +1,4 @@
A sesssion-fixture which can look at all collected tests
A session-fixture which can look at all collected tests
----------------------------------------------------------------
A session-scoped fixture effectively has access to all
@@ -61,13 +60,26 @@ will be called ahead of running any tests::
If you run this without output capturing::
$ py.test -q -s test_module.py
callattr_ahead_of_alltests called
callme called!
callme other called
SomeTest callme called
test_method1 called
.test_method1 called
.test other
.test_unit1 method called
.
4 passed in 0.01 seconds
Traceback (most recent call last):
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/config.py", line 513, in getconftestmodules
return self._path2confmods[path]
KeyError: local('/tmp/doc-exec-244/test_module.py')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/config.py", line 537, in importconftest
return self._conftestpath2mod[conftestpath]
KeyError: local('/tmp/doc-exec-244/conftest.py')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/config.py", line 543, in importconftest
mod = conftestpath.pyimport()
File "/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/py/_path/local.py", line 620, in pyimport
__import__(modname)
File "/tmp/doc-exec-244/conftest.py", line 6
print "callattr_ahead_of_alltests called"
^
SyntaxError: invalid syntax
ERROR: could not load /tmp/doc-exec-244/conftest.py

View File

@@ -23,3 +23,8 @@ def test_hello5():
def test_hello6():
pytest.xfail("reason")
@xfail(raises=IndexError)
def test_hello7():
x = []
x[1] = 1

View File

@@ -4,37 +4,37 @@ Some Issues and Questions
.. note::
This FAQ is here only mostly for historic reasons. Checkout
`pytest Q&A at Stackoverflow <http://stackoverflow.com/search?q=pytest>`_
`pytest Q&A at Stackoverflow <http://stackoverflow.com/search?q=pytest>`_
for many questions and answers related to pytest and/or use
:ref:`contact channels` to get help.
On naming, nosetests, licensing and magic
------------------------------------------------
How does py.test relate to nose and unittest?
How does pytest relate to nose and unittest?
+++++++++++++++++++++++++++++++++++++++++++++++++
py.test and nose_ share basic philosophy when it comes
``pytest`` and nose_ share basic philosophy when it comes
to running and writing Python tests. In fact, you can run many tests
written for nose with py.test. nose_ was originally created
as a clone of ``py.test`` when py.test was in the ``0.8`` release
written for nose with ``pytest``. nose_ was originally created
as a clone of ``pytest`` when ``pytest`` was in the ``0.8`` release
cycle. Note that starting with pytest-2.0 support for running unittest
test suites is majorly improved.
how does py.test relate to twisted's trial?
how does pytest relate to twisted's trial?
++++++++++++++++++++++++++++++++++++++++++++++
Since some time py.test has builtin support for supporting tests
Since some time ``pytest`` has builtin support for supporting tests
written using trial. It does not itself start a reactor, however,
and does not handle Deferreds returned from a test in pytest style.
and does not handle Deferreds returned from a test in pytest style.
If you are using trial's unittest.TestCase chances are that you can
just run your tests even if you return Deferreds. In addition,
there also is a dedicated `pytest-twisted
<http://pypi.python.org/pypi/pytest-twisted>`_ plugin which allows to
return deferreds from pytest-style tests, allowing to use
:ref:`fixtures` and other features.
how does py.test work with Django?
how does pytest work with Django?
++++++++++++++++++++++++++++++++++++++++++++++
In 2012, some work is going into the `pytest-django plugin <http://pypi.python.org/pypi/pytest-django>`_. It substitutes the usage of Django's
@@ -44,36 +44,36 @@ are not available from Django directly.
.. _features: features.html
What's this "magic" with py.test? (historic notes)
What's this "magic" with pytest? (historic notes)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Around 2007 (version ``0.8``) some people thought that py.test
Around 2007 (version ``0.8``) some people thought that ``pytest``
was using too much "magic". It had been part of the `pylib`_ which
contains a lot of unreleated python library code. Around 2010 there
was a major cleanup refactoring, which removed unused or deprecated code
was a major cleanup refactoring, which removed unused or deprecated code
and resulted in the new ``pytest`` PyPI package which strictly contains
only test-related code. This relese also brought a complete pluginification
only test-related code. This release also brought a complete pluginification
such that the core is around 300 lines of code and everything else is
implemented in plugins. Thus ``pytest`` today is a small, universally runnable
implemented in plugins. Thus ``pytest`` today is a small, universally runnable
and customizable testing framework for Python. Note, however, that
``pytest`` uses metaprogramming techniques and reading its source is
``pytest`` uses metaprogramming techniques and reading its source is
thus likely not something for Python beginners.
A second "magic" issue was the assert statement debugging feature.
Nowadays, py.test explicitely rewrites assert statements in test modules
A second "magic" issue was the assert statement debugging feature.
Nowadays, ``pytest`` explicitely rewrites assert statements in test modules
in order to provide more useful :ref:`assert feedback <assertfeedback>`.
This completely avoids previous issues of confusing assertion-reporting.
This completely avoids previous issues of confusing assertion-reporting.
It also means, that you can use Python's ``-O`` optimization without loosing
assertions in test modules.
py.test contains a second mostly obsolete assert debugging technique,
``pytest`` contains a second, mostly obsolete, assert debugging technique,
invoked via ``--assert=reinterpret``, activated by default on
Python-2.5: When an ``assert`` statement fails, py.test re-interprets
Python-2.5: When an ``assert`` statement fails, ``pytest`` re-interprets
the expression part to show intermediate values. This technique suffers
from a caveat that the rewriting does not: If your expression has side
effects (better to avoid them anyway!) the intermediate values may not
be the same, confusing the reinterpreter and obfuscating the initial
error (this is also explained at the command line if it happens).
error (this is also explained at the command line if it happens).
You can also turn off all assertion interaction using the
``--assertmode=off`` option.
@@ -85,7 +85,7 @@ You can also turn off all assertion interaction using the
Why a ``py.test`` instead of a ``pytest`` command?
++++++++++++++++++++++++++++++++++++++++++++++++++
Some of the reasons are historic, others are practical. ``py.test``
Some of the reasons are historic, others are practical. ``pytest``
used to be part of the ``py`` package which provided several developer
utilities, all starting with ``py.<TAB>``, thus providing nice
TAB-completion. If
@@ -140,16 +140,16 @@ However, with pytest-2.3 you can use the :ref:`@pytest.fixture` decorator
and specify ``params`` so that all tests depending on the factory-created
resource will run multiple times with different parameters.
You can also use the `pytest_generate_tests`_ hook to
You can also use the `pytest_generate_tests`_ hook to
implement the `parametrization scheme of your choice`_.
.. _`pytest_generate_tests`: test/funcargs.html#parametrizing-tests
.. _`parametrization scheme of your choice`: http://tetamap.wordpress.com/2009/05/13/parametrizing-python-tests-generalized/
py.test interaction with other packages
pytest interaction with other packages
---------------------------------------------------
Issues with py.test, multiprocess and setuptools?
Issues with pytest, multiprocess and setuptools?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
On windows the multiprocess package will instantiate sub processes

View File

@@ -15,7 +15,7 @@ pytest fixtures: explicit, modular, scalable
The `purpose of test fixtures`_ is to provide a fixed baseline
upon which tests can reliably and repeatedly execute. pytest fixtures
offer dramatic improvements over the classic xUnit style of setup/teardown
offer dramatic improvements over the classic xUnit style of setup/teardown
functions:
* fixtures have explicit names and are activated by declaring their use
@@ -50,7 +50,7 @@ Fixtures as Function arguments
-----------------------------------------
Test functions can receive fixture objects by naming them as an input
argument. For each argument name, a fixture function with that name provides
argument. For each argument name, a fixture function with that name provides
the fixture object. Fixture functions are registered by marking them with
:py:func:`@pytest.fixture <_pytest.python.fixture>`. Let's look at a simple
self-contained test module containing a fixture and a test function
@@ -70,13 +70,13 @@ using it::
assert "merlinux" in msg
assert 0 # for demo purposes
Here, the ``test_ehlo`` needs the ``smtp`` fixture value. pytest
will discover and call the :py:func:`@pytest.fixture <_pytest.python.fixture>`
Here, the ``test_ehlo`` needs the ``smtp`` fixture value. pytest
will discover and call the :py:func:`@pytest.fixture <_pytest.python.fixture>`
marked ``smtp`` fixture function. Running the test looks like this::
$ py.test test_smtpsimple.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.2.dev1
collected 1 items
test_smtpsimple.py F
@@ -84,22 +84,21 @@ marked ``smtp`` fixture function. Running the test looks like this::
================================= FAILURES =================================
________________________________ test_ehlo _________________________________
smtp = <smtplib.SMTP instance at 0x2ae3469203f8>
smtp = <smtplib.SMTP object at 0x2ade77b37e48>
def test_ehlo(smtp):
response, msg = smtp.ehlo()
assert response == 250
assert "merlinux" in msg
> assert 0 # for demo purposes
E assert 0
> assert "merlinux" in msg
E TypeError: Type str doesn't support the buffer API
test_smtpsimple.py:12: AssertionError
========================= 1 failed in 0.21 seconds =========================
test_smtpsimple.py:11: TypeError
========================= 1 failed in 0.18 seconds =========================
In the failure traceback we see that the test function was called with a
``smtp`` argument, the ``smtplib.SMTP()`` instance created by the fixture
function. The test function fails on our deliberate ``assert 0``. Here is
an exact protocol of how py.test comes to call the test function this way:
the exact protocol used by ``pytest`` to call the test function this way:
1. pytest :ref:`finds <test discovery>` the ``test_ehlo`` because
of the ``test_`` prefix. The test function needs a function argument
@@ -125,7 +124,7 @@ with a list of available function arguments.
In versions prior to 2.3 there was no ``@pytest.fixture`` marker
and you had to use a magic ``pytest_funcarg__NAME`` prefix
for the fixture factory. This remains and will remain supported
for the fixture factory. This remains and will remain supported
but is not anymore advertised as the primary means of declaring fixture
functions.
@@ -153,15 +152,15 @@ Sharing a fixture across tests in a module (or class/session)
.. regendoc:wipe
Fixtures requiring network access depend on connectivity and are
Fixtures requiring network access depend on connectivity and are
usually time-expensive to create. Extending the previous example, we
can add a ``scope='module'`` parameter to the
can add a ``scope='module'`` parameter to the
:py:func:`@pytest.fixture <_pytest.python.fixture>` invocation
to cause the decorated ``smtp`` fixture function to only be invoked once
to cause the decorated ``smtp`` fixture function to only be invoked once
per test module. Multiple test functions in a test module will thus
each receive the same ``smtp`` fixture instance. The next example puts
the fixture function into a separate ``conftest.py`` file so
that tests from multiple test modules in the directory can
that tests from multiple test modules in the directory can
access the fixture function::
# content of conftest.py
@@ -180,7 +179,7 @@ function (in or below the directory where ``conftest.py`` is located)::
def test_ehlo(smtp):
response = smtp.ehlo()
assert response[0] == 250
assert response[0] == 250
assert "merlinux" in response[1]
assert 0 # for demo purposes
@@ -194,7 +193,7 @@ inspect what is going on and can now run the tests::
$ py.test test_module.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.2.dev1
collected 2 items
test_module.py FF
@@ -202,19 +201,18 @@ inspect what is going on and can now run the tests::
================================= FAILURES =================================
________________________________ test_ehlo _________________________________
smtp = <smtplib.SMTP instance at 0x1af5440>
smtp = <smtplib.SMTP object at 0x2b4b07e38e48>
def test_ehlo(smtp):
response = smtp.ehlo()
assert response[0] == 250
assert "merlinux" in response[1]
> assert 0 # for demo purposes
E assert 0
> assert "merlinux" in response[1]
E TypeError: Type str doesn't support the buffer API
test_module.py:6: AssertionError
test_module.py:5: TypeError
________________________________ test_noop _________________________________
smtp = <smtplib.SMTP instance at 0x1af5440>
smtp = <smtplib.SMTP object at 0x2b4b07e38e48>
def test_noop(smtp):
response = smtp.noop()
@@ -223,11 +221,11 @@ inspect what is going on and can now run the tests::
E assert 0
test_module.py:11: AssertionError
========================= 2 failed in 0.17 seconds =========================
========================= 2 failed in 0.18 seconds =========================
You see the two ``assert 0`` failing and more importantly you can also see
that the same (module-scoped) ``smtp`` object was passed into the two
test functions because pytest shows the incoming argument values in the
You see the two ``assert 0`` failing and more importantly you can also see
that the same (module-scoped) ``smtp`` object was passed into the two
test functions because pytest shows the incoming argument values in the
traceback. As a result, the two test functions using ``smtp`` run as
quick as a single one because they reuse the same instance.
@@ -236,15 +234,15 @@ instance, you can simply declare it::
@pytest.fixture(scope="session")
def smtp(...):
# the returned fixture value will be shared for
# the returned fixture value will be shared for
# all tests needing it
.. _`finalization`:
fixture finalization / executing teardown code
fixture finalization / executing teardown code
-------------------------------------------------------------
pytest supports execution of fixture specific finalization code
pytest supports execution of fixture specific finalization code
when the fixture goes out of scope. By accepting a ``request`` object
into your fixture function you can call its ``request.addfinalizer`` one
or multiple times::
@@ -271,12 +269,12 @@ Let's execute it::
$ py.test -s -q --tb=no
FFteardown smtp
2 failed in 0.17 seconds
2 failed in 0.16 seconds
We see that the ``smtp`` instance is finalized after the two
tests finished execution. Note that if we decorated our fixture
function with ``scope='function'`` then fixture setup and cleanup would
occur around each single test. In either case the test
occur around each single test. In either case the test
module itself does not need to change or know about these details
of fixture setup.
@@ -288,7 +286,7 @@ Fixtures can introspect the requesting test context
Fixture function can accept the :py:class:`request <FixtureRequest>` object
to introspect the "requesting" test function, class or module context.
Further extending the previous ``smtp`` fixture example, let's
Further extending the previous ``smtp`` fixture example, let's
read an optional server URL from the test module which uses our fixture::
# content of conftest.py
@@ -299,12 +297,12 @@ read an optional server URL from the test module which uses our fixture::
def smtp(request):
server = getattr(request.module, "smtpserver", "merlinux.eu")
smtp = smtplib.SMTP(server)
def fin():
print ("finalizing %s (%s)" % (smtp, server))
smtp.close()
return smtp
return smtp
We use the ``request.module`` attribute to optionally obtain an
``smtpserver`` attribute from the test module. If we just execute
@@ -312,13 +310,13 @@ again, nothing much has changed::
$ py.test -s -q --tb=no
FF
2 failed in 0.21 seconds
2 failed in 0.17 seconds
Let's quickly create another test module that actually sets the
server URL in its module namespace::
# content of test_anothersmtp.py
smtpserver = "mail.python.org" # will be read by smtp fixture
def test_showhelo(smtp):
@@ -331,8 +329,8 @@ Running it::
================================= FAILURES =================================
______________________________ test_showhelo _______________________________
test_anothersmtp.py:5: in test_showhelo
> assert 0, smtp.helo()
E AssertionError: (250, 'mail.python.org')
assert 0, smtp.helo()
E AssertionError: (250, b'mail.python.org')
voila! The ``smtp`` fixture function picked up our mail server name
from the module namespace.
@@ -346,7 +344,7 @@ Fixture functions can be parametrized in which case they will be called
multiple times, each time executing the set of dependent tests, i. e. the
tests that depend on this fixture. Test functions do usually not need
to be aware of their re-running. Fixture parametrization helps to
write exhaustive functional tests for components which themselves can be
write exhaustive functional tests for components which themselves can be
configured in multiple ways.
Extending the previous example, we can flag the fixture to create two
@@ -358,7 +356,7 @@ through the special :py:class:`request <FixtureRequest>` object::
import pytest
import smtplib
@pytest.fixture(scope="module",
@pytest.fixture(scope="module",
params=["merlinux.eu", "mail.python.org"])
def smtp(request):
smtp = smtplib.SMTP(request.param)
@@ -368,10 +366,10 @@ through the special :py:class:`request <FixtureRequest>` object::
request.addfinalizer(fin)
return smtp
The main change is the declaration of ``params`` with
The main change is the declaration of ``params`` with
:py:func:`@pytest.fixture <_pytest.python.fixture>`, a list of values
for each of which the fixture function will execute and can access
a value via ``request.param``. No test function code needs to change.
a value via ``request.param``. No test function code needs to change.
So let's just do another run::
$ py.test -q test_module.py
@@ -379,19 +377,18 @@ So let's just do another run::
================================= FAILURES =================================
__________________________ test_ehlo[merlinux.eu] __________________________
smtp = <smtplib.SMTP instance at 0x100ac20>
smtp = <smtplib.SMTP object at 0x2b824acf3e80>
def test_ehlo(smtp):
response = smtp.ehlo()
assert response[0] == 250
assert "merlinux" in response[1]
> assert 0 # for demo purposes
E assert 0
> assert "merlinux" in response[1]
E TypeError: Type str doesn't support the buffer API
test_module.py:6: AssertionError
test_module.py:5: TypeError
__________________________ test_noop[merlinux.eu] __________________________
smtp = <smtplib.SMTP instance at 0x100ac20>
smtp = <smtplib.SMTP object at 0x2b824acf3e80>
def test_noop(smtp):
response = smtp.noop()
@@ -402,20 +399,20 @@ So let's just do another run::
test_module.py:11: AssertionError
________________________ test_ehlo[mail.python.org] ________________________
smtp = <smtplib.SMTP instance at 0x105b638>
smtp = <smtplib.SMTP object at 0x2b824b19fb38>
def test_ehlo(smtp):
response = smtp.ehlo()
assert response[0] == 250
> assert "merlinux" in response[1]
E assert 'merlinux' in 'mail.python.org\nSIZE 25600000\nETRN\nSTARTTLS\nENHANCEDSTATUSCODES\n8BITMIME\nDSN'
E TypeError: Type str doesn't support the buffer API
test_module.py:5: AssertionError
----------------------------- Captured stdout ------------------------------
finalizing <smtplib.SMTP instance at 0x100ac20>
test_module.py:5: TypeError
-------------------------- Captured stdout setup ---------------------------
finalizing <smtplib.SMTP object at 0x2b824acf3e80>
________________________ test_noop[mail.python.org] ________________________
smtp = <smtplib.SMTP instance at 0x105b638>
smtp = <smtplib.SMTP object at 0x2b824b19fb38>
def test_noop(smtp):
response = smtp.noop()
@@ -424,11 +421,11 @@ So let's just do another run::
E assert 0
test_module.py:11: AssertionError
4 failed in 6.58 seconds
4 failed in 6.37 seconds
We see that our two test functions each ran twice, against the different
``smtp`` instances. Note also, that with the ``mail.python.org``
connection the second test fails in ``test_ehlo`` because a
``smtp`` instances. Note also, that with the ``mail.python.org``
connection the second test fails in ``test_ehlo`` because a
different server string is expected than what arrived.
@@ -445,7 +442,7 @@ and instantiate an object ``app`` where we stick the already defined
``smtp`` resource into it::
# content of test_appsetup.py
import pytest
class App:
@@ -464,22 +461,22 @@ Here we declare an ``app`` fixture which receives the previously defined
$ py.test -v test_appsetup.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.2.dev1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 2 items
test_appsetup.py:12: test_smtp_exists[merlinux.eu] PASSED
test_appsetup.py:12: test_smtp_exists[mail.python.org] PASSED
test_appsetup.py::test_smtp_exists[merlinux.eu] PASSED
test_appsetup.py::test_smtp_exists[mail.python.org] PASSED
========================= 2 passed in 5.95 seconds =========================
========================= 2 passed in 6.11 seconds =========================
Due to the parametrization of ``smtp`` the test will run twice with two
different ``App`` instances and respective smtp servers. There is no
need for the ``app`` fixture to be aware of the ``smtp`` parametrization
as pytest will fully analyse the fixture dependency graph.
need for the ``app`` fixture to be aware of the ``smtp`` parametrization
as pytest will fully analyse the fixture dependency graph.
Note, that the ``app`` fixture has a scope of ``module`` and uses a
module-scoped ``smtp`` fixture. The example would still work if ``smtp``
was cached on a ``session`` scope: it is fine for fixtures to use
was cached on a ``session`` scope: it is fine for fixtures to use
"broader" scoped fixtures but not the other way round:
A session-scoped fixture could not use a module-scoped one in a
meaningful way.
@@ -494,11 +491,11 @@ Automatic grouping of tests by fixture instances
pytest minimizes the number of active fixtures during test runs.
If you have a parametrized fixture, then all the tests using it will
first execute with one instance and then finalizers are called
first execute with one instance and then finalizers are called
before the next fixture instance is created. Among other things,
this eases testing of applications which create and use global state.
The following example uses two parametrized funcargs, one of which is
The following example uses two parametrized funcargs, one of which is
scoped on a per-module basis, and all the functions perform ``print`` calls
to show the setup/teardown flow::
@@ -508,7 +505,7 @@ to show the setup/teardown flow::
@pytest.fixture(scope="module", params=["mod1", "mod2"])
def modarg(request):
param = request.param
print "create", param
print ("create", param)
def fin():
print ("fin %s" % param)
return param
@@ -518,42 +515,42 @@ to show the setup/teardown flow::
return request.param
def test_0(otherarg):
print " test0", otherarg
print (" test0", otherarg)
def test_1(modarg):
print " test1", modarg
print (" test1", modarg)
def test_2(otherarg, modarg):
print " test2", otherarg, modarg
print (" test2", otherarg, modarg)
Let's run the tests in verbose mode and with looking at the print-output::
$ py.test -v -s test_module.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1 -- /home/hpk/p/pytest/.tox/regen/bin/python
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.2.dev1 -- /home/hpk/p/pytest/.tox/regen/bin/python3.4
collecting ... collected 8 items
test_module.py:15: test_0[1] test0 1
test_module.py::test_0[1] test0 1
PASSED
test_module.py:15: test_0[2] test0 2
test_module.py::test_0[2] test0 2
PASSED
test_module.py:17: test_1[mod1] create mod1
test_module.py::test_1[mod1] create mod1
test1 mod1
PASSED
test_module.py:19: test_2[1-mod1] test2 1 mod1
test_module.py::test_2[1-mod1] test2 1 mod1
PASSED
test_module.py:19: test_2[2-mod1] test2 2 mod1
test_module.py::test_2[2-mod1] test2 2 mod1
PASSED
test_module.py:17: test_1[mod2] create mod2
test_module.py::test_1[mod2] create mod2
test1 mod2
PASSED
test_module.py:19: test_2[1-mod2] test2 1 mod2
test_module.py::test_2[1-mod2] test2 1 mod2
PASSED
test_module.py:19: test_2[2-mod2] test2 2 mod2
test_module.py::test_2[2-mod2] test2 2 mod2
PASSED
========================= 8 passed in 0.01 seconds =========================
You can see that the parametrized module-scoped ``modarg`` resource caused
an ordering of test execution that lead to the fewest possible "active" resources. The finalizer for the ``mod1`` parametrized resource was executed
an ordering of test execution that lead to the fewest possible "active" resources. The finalizer for the ``mod1`` parametrized resource was executed
before the ``mod2`` resource was setup.
@@ -573,7 +570,7 @@ achieve it. We separate the creation of the fixture into a conftest.py
file::
# content of conftest.py
import pytest
import tempfile
import os
@@ -612,12 +609,12 @@ You can specify multiple fixtures like this::
@pytest.mark.usefixtures("cleandir", "anotherfixture")
and you may specify fixture usage at the test module level, using
and you may specify fixture usage at the test module level, using
a generic feature of the mark mechanism::
pytestmark = pytest.mark.usefixtures("cleandir")
Lastly you can put fixtures required by all tests in your project
Lastly you can put fixtures required by all tests in your project
into an ini-file::
# content of pytest.ini
@@ -635,14 +632,14 @@ autouse fixtures (xUnit setup on steroids)
.. regendoc:wipe
Occasionally, you may want to have fixtures get invoked automatically
without a `usefixtures`_ or `funcargs`_ reference. As a practical
without a `usefixtures`_ or `funcargs`_ reference. As a practical
example, suppose we have a database fixture which has a
begin/rollback/commit architecture and we want to automatically surround
each test method by a transaction and a rollback. Here is a dummy
self-contained implementation of this idea::
# content of test_db_transact.py
import pytest
class DB:
@@ -682,11 +679,11 @@ If we run it, we get two passing tests::
Here is how autouse fixtures work in other scopes:
- if an autouse fixture is defined in a test module, all its test
functions automatically use it.
- if an autouse fixture is defined in a test module, all its test
functions automatically use it.
- if an autouse fixture is defined in a conftest.py file then all tests in
all test modules belows its directory will invoke the fixture.
- if an autouse fixture is defined in a conftest.py file then all tests in
all test modules belows its directory will invoke the fixture.
- lastly, and **please use that with care**: if you define an autouse
fixture in a plugin, it will be invoked for all tests in all projects
@@ -697,7 +694,7 @@ Here is how autouse fixtures work in other scopes:
Note that the above ``transact`` fixture may very well be a fixture that
you want to make available in your project without having it generally
active. The canonical way to do that is to put the transact definition
active. The canonical way to do that is to put the transact definition
into a conftest.py file **without** using ``autouse``::
# content of conftest.py
@@ -714,7 +711,7 @@ and then e.g. have a TestClass using it by declaring the need::
...
All test methods in this TestClass will use the transaction fixture while
other test classes or functions in the module will not use it unless
other test classes or functions in the module will not use it unless
they also add a ``transact`` reference.
Shifting (visibility of) fixture functions

View File

@@ -1,12 +1,16 @@
Installation and Getting Started
===================================
**Pythons**: Python 2.5-3.3, Jython, PyPy
**Pythons**: Python 2.6-3.4, Jython, PyPy-2.3
**Platforms**: Unix/Posix and Windows
**PyPI package name**: `pytest <http://pypi.python.org/pypi/pytest>`_
**dependencies**: `py <http://pypi.python.org/pypi/py>`_,
`colorama (Windows) <http://pypi.python.org/pypi/colorama>`_,
`argparse (py26) <http://pypi.python.org/pypi/argparse>`_.
**documentation as PDF**: `download latest <http://pytest.org/latest/pytest.pdf>`_
.. _`getstarted`:
@@ -23,7 +27,7 @@ Installation options::
To check your installation has installed the correct version::
$ py.test --version
This is py.test version 2.5.1, imported from /home/hpk/p/pytest/.tox/regen/local/lib/python2.7/site-packages/pytest.pyc
This is pytest version 2.6.1, imported from /home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/pytest.py
If you get an error checkout :ref:`installation issues`.
@@ -45,23 +49,23 @@ That's it. You can execute the test function now::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 1 items
test_sample.py F
================================= FAILURES =================================
_______________________________ test_answer ________________________________
def test_answer():
> assert func(3) == 5
E assert 4 == 5
E + where 4 = func(3)
test_sample.py:5: AssertionError
========================= 1 failed in 0.01 seconds =========================
py.test found the ``test_answer`` function by following :ref:`standard test discovery rules <test discovery>`, basically detecting the ``test_`` prefixes. We got a failure report because our little ``func(3)`` call did not return ``5``.
``pytest`` found the ``test_answer`` function by following :ref:`standard test discovery rules <test discovery>`, basically detecting the ``test_`` prefixes. We got a failure report because our little ``func(3)`` call did not return ``5``.
.. note::
@@ -122,14 +126,14 @@ run the module by passing its filename::
.F
================================= FAILURES =================================
____________________________ TestClass.test_two ____________________________
self = <test_class.TestClass instance at 0x2b57dd0>
self = <test_class.TestClass object at 0x2ad4b005b710>
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.01 seconds
@@ -142,34 +146,31 @@ Going functional: requesting a unique temporary directory
For functional tests one often needs to create some files
and pass them to application objects. pytest provides
:ref:`builtinfixtures` which allow to request arbitrary
:ref:`builtinfixtures` which allow to request arbitrary
resources, for example a unique temporary directory::
# content of test_tmpdir.py
def test_needsfiles(tmpdir):
print tmpdir
print (tmpdir)
assert 0
We list the name ``tmpdir`` in the test function signature and
py.test will lookup and call a fixture factory to create the resource
``pytest`` will lookup and call a fixture factory to create the resource
before performing the test function call. Let's just run it::
$ py.test -q test_tmpdir.py
F
================================= FAILURES =================================
_____________________________ test_needsfiles ______________________________
tmpdir = local('/tmp/pytest-38/test_needsfiles0')
def test_needsfiles(tmpdir):
print tmpdir
> assert 0
E assert 0
test_tmpdir.py:3: AssertionError
----------------------------- Captured stdout ------------------------------
/tmp/pytest-38/test_needsfiles0
1 failed in 0.04 seconds
================================== ERRORS ==================================
_____________________ ERROR collecting test_tmpdir.py ______________________
/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/python.py:463: in _importtestmodule
mod = self.fspath.pyimport(ensuresyspath=True)
/home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/py/_path/local.py:620: in pyimport
__import__(modname)
E File "/tmp/doc-exec-187/test_tmpdir.py", line 2
E print tmpdir
E ^
E SyntaxError: invalid syntax
1 error in 0.03 seconds
Before the test runs, a unique-per-test-invocation temporary directory
was created. More info at :ref:`tmpdir handling`.
@@ -186,7 +187,7 @@ Here are a few suggestions where to go next:
* :ref:`cmdline` for command line invocation examples
* :ref:`good practises <goodpractises>` for virtualenv, test layout, genscript support
* :ref:`fixtures` for providing a functional baseline to your tests
* :ref:`apiref` for documentation and examples on using py.test
* :ref:`apiref` for documentation and examples on using ``pytest``
* :ref:`plugins` managing and writing plugins
.. _`installation issues`:
@@ -221,7 +222,7 @@ py.test not found on Windows despite installation?
- **Jython2.5.1 on Windows XP**: `Jython does not create command line launchers`_
so ``py.test`` will not work correctly. You may install py.test on
CPython and type ``py.test --genscript=mytest`` and then use
``jython mytest`` to run py.test for your tests to run with Jython.
``jython mytest`` to run your tests with Jython using ``pytest``.
:ref:`examples` for more complex examples

View File

@@ -1,4 +1,3 @@
.. highlightlang:: python
.. _`goodpractises`:
@@ -8,8 +7,8 @@ Good Integration Practises
Work with virtual environments
-----------------------------------------------------------
We recommend to use virtualenv_ environments and use pip_
(or easy_install_) for installing your application and any dependencies
We recommend to use virtualenv_ environments and use pip_
(or easy_install_) for installing your application and any dependencies
as well as the ``pytest`` package itself. This way you will get an isolated
and reproducible environment. Given you have installed virtualenv_
and execute it from the command line, here is an example session for unix
@@ -27,19 +26,19 @@ We can now install pytest::
Due to the ``activate`` step above the ``pip`` will come from
the virtualenv directory and install any package into the isolated
virtual environment.
virtual environment.
Choosing a test layout / import rules
------------------------------------------
py.test supports two common test layouts:
``pytest`` supports two common test layouts:
* putting tests into an extra directory outside your actual application
code, useful if you have many functional tests or for other reasons
want to keep tests separate from actual application code (often a good
idea)::
setup.py # your distutils/setuptools Python package metadata
setup.py # your distutils/setuptools Python package metadata
mypkg/
__init__.py
appmodule.py
@@ -48,11 +47,11 @@ py.test supports two common test layouts:
...
* inlining test directories into your application package, useful if you
* inlining test directories into your application package, useful if you
have direct relation between (unit-)test and application modules and
want to distribute your tests along with your application::
setup.py # your distutils/setuptools Python package metadata
setup.py # your distutils/setuptools Python package metadata
mypkg/
__init__.py
appmodule.py
@@ -68,11 +67,11 @@ Important notes relating to both schemes:
pip install -e . # install package using setup.py in editable mode
- **avoid "__init__.py" files in your test directories**.
This way your tests can run easily against an installed version
of ``mypkg``, independently from if the installed package contains
the tests or not.
This way your tests can run easily against an installed version
of ``mypkg``, independently from the installed package if it contains
the tests or not.
- With inlined tests you might put ``__init__.py`` into test
- With inlined tests you might put ``__init__.py`` into test
directories and make them installable as part of your application.
Using the ``py.test --pyargs mypkg`` invocation pytest will
discover where mypkg is installed and collect tests from there.
@@ -87,19 +86,19 @@ Typically you can run tests by pointing to test directories or modules::
py.test # run all tests below current dir
...
Because of the above ``editable install`` mode you can change your
Because of the above ``editable install`` mode you can change your
source code (both tests and the app) and rerun tests at will.
Once you are done with your work, you can `use tox`_ to make sure
that the package is really correct and tests pass in all
that the package is really correct and tests pass in all
required configurations.
.. note::
You can use Python3 namespace packages (PEP420) for your application
but pytest will still perform `test package name`_ discovery based on the
presence of ``__init__.py`` files. If you use one of the
presence of ``__init__.py`` files. If you use one of the
two recommended file system layouts above but leave away the ``__init__.py``
files from your directories it should just work on Python3.3 and above. From
files from your directories it should just work on Python3.3 and above. From
"inlined tests", however, you will need to use absolute imports for
getting at your application code.
@@ -107,7 +106,7 @@ required configurations.
.. note::
If py.test finds a "a/b/test_module.py" test file while
If ``pytest`` finds a "a/b/test_module.py" test file while
recursing into the filesystem it determines the import name
as follows:
@@ -155,17 +154,17 @@ to create a JUnitXML file that Jenkins_ can pick up and generate reports.
.. _standalone:
.. _`genscript method`:
Create a py.test standalone script
Create a pytest standalone script
-------------------------------------------
If you are a maintainer or application developer and want people
who don't deal with python much to easily run tests you may generate
a standalone "py.test" script::
who don't deal with python much to easily run tests you may generate
a standalone ``pytest`` script::
py.test --genscript=runtests.py
This generates a ``runtests.py`` script which is a fully functional basic
``py.test`` script, running unchanged under Python2 and Python3.
``pytest`` script, running unchanged under Python2 and Python3.
You can tell people to download the script and then e.g. run it like this::
python runtests.py
@@ -176,7 +175,7 @@ Integrating with distutils / ``python setup.py test``
You can integrate test runs into your distutils or
setuptools based project. Use the `genscript method`_
to generate a standalone py.test script::
to generate a standalone ``pytest`` script::
py.test --genscript=runtests.py
@@ -190,12 +189,16 @@ this to your ``setup.py`` file::
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import sys,subprocess
errno = subprocess.call([sys.executable, 'runtests.py'])
raise SystemExit(errno)
setup(
#...,
cmdclass = {'test': PyTest},
@@ -207,7 +210,7 @@ If you now type::
python setup.py test
this will execute your tests using ``runtests.py``. As this is a
standalone version of ``py.test`` no prior installation whatsoever is
standalone version of ``pytest`` no prior installation whatsoever is
required for calling the test command. You can also pass additional
arguments to the subprocess-calls such as your test directory or other
options.
@@ -220,20 +223,30 @@ Setuptools supports writing our own Test command for invoking pytest.
Most often it is better to use tox_ instead, but here is how you can
get started with setuptools integration::
from setuptools.command.test import test as TestCommand
import sys
from setuptools.command.test import test as TestCommand
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = None
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
#import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
errno = pytest.main(self.pytest_args)
sys.exit(errno)
setup(
#...,
tests_require=['pytest'],
@@ -244,8 +257,13 @@ Now if you run::
python setup.py test
this will download py.test if needed and then run py.test
as you would expect it to.
this will download ``pytest`` if needed and then run your tests
as you would expect it to. You can pass a single string of arguments
using the ``--pytest-args`` or ``-a`` command-line option. For example::
python setup.py test -a "--durations=5"
is equivalent to running ``py.test --durations=5``.
.. _`test discovery`:
.. _`Python test discovery`:
@@ -253,7 +271,7 @@ as you would expect it to.
Conventions for Python test discovery
-------------------------------------------------
``py.test`` implements the following standard test discovery:
``pytest`` implements the following standard test discovery:
* collection starts from the initial command line arguments
which may be directories, filenames or test ids.
@@ -264,7 +282,7 @@ Conventions for Python test discovery
For examples of how to customize your test discovery :doc:`example/pythoncollection`.
Within Python modules, py.test also discovers tests using the standard
Within Python modules, ``pytest`` also discovers tests using the standard
:ref:`unittest.TestCase <unittest.TestCase>` subclassing technique.
.. include:: links.inc

BIN
doc/en/img/pullrequest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
doc/en/img/pytest1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
doc/en/img/pytest1favi.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@@ -1,24 +1,27 @@
.. _features:
.. second training: `professional testing with Python <http://www.python-academy.com/courses/specialtopics/python_course_testing.html>`_ , 25-27th November 2013, Leipzig.
.. note::
next training: `professional testing with pytest and tox <http://www.python-academy.com/courses/specialtopics/python_course_testing.html>`_, 24-26th November 2014, Freiburg, Germany
pytest: helps you write better programs
=============================================
**a mature full-featured Python testing tool**
- runs on Posix/Windows, Python 2.5-3.3, PyPy and Jython-2.5.1
- **zero-reported-bugs** policy with >1000 tests against itself
- runs on Posix/Windows, Python 2.6-3.4, PyPy and (possibly still) Jython-2.5.1
- **well tested** with more than a thousand tests against itself
- **strict backward compatibility policy** for safe pytest upgrades
- :ref:`comprehensive online <toc>` and `PDF documentation <pytest.pdf>`_
- many :ref:`third party plugins <extplugins>` and :ref:`builtin helpers <pytest helpers>`,
- many :ref:`third party plugins <extplugins>` and :ref:`builtin helpers <pytest helpers>`,
- used in :ref:`many small and large projects and organisations <projects>`
- comes with many :ref:`tested examples <examples>`
**provides easy no-boilerplate testing**
- makes it :ref:`easy to get started <getstarted>`,
- makes it :ref:`easy to get started <getstarted>`,
has many :ref:`usage options <usage>`
- :ref:`assert with the assert statement`
- helpful :ref:`traceback and failing assertion reporting <tbreportdemo>`
@@ -38,7 +41,7 @@ pytest: helps you write better programs
**integrates with other testing methods and tools**:
- multi-paradigm: pytest can run ``nose``, ``unittest`` and
- multi-paradigm: pytest can run ``nose``, ``unittest`` and
``doctest`` style test suites, including running testcases made for
Django and trial
- supports :ref:`good integration practises <goodpractises>`

View File

@@ -48,7 +48,7 @@ requests in all your tests, you can do::
import pytest
@pytest.fixture(autouse=True)
def no_requests(monkeypatch):
monkeypatch.delattr("requests.session.Session.request")
monkeypatch.delattr("requests.sessions.Session.request")
This autouse fixture will be executed for each test function and it
will delete the method ``request.session.Session.request``

View File

@@ -3,7 +3,7 @@ Running tests written for nose
.. include:: links.inc
py.test has basic support for running tests written for nose_.
``pytest`` has basic support for running tests written for nose_.
.. _nosestyle:
@@ -16,7 +16,7 @@ After :ref:`installation` type::
py.test # instead of 'nosetests'
and you should be able to run your nose style tests and
make use of py.test's capabilities.
make use of pytest's capabilities.
Supported nose Idioms
----------------------
@@ -25,15 +25,16 @@ Supported nose Idioms
* SkipTest exceptions and markers
* setup/teardown decorators
* yield-based tests and their setup
* ``__test__`` attribute on modules/classes/functions
* general usage of nose utilities
Unsupported idioms / known issues
----------------------------------
- unittest-style ``setUp, tearDown, setUpClass, tearDownClass``
- unittest-style ``setUp, tearDown, setUpClass, tearDownClass``
are recognized only on ``unittest.TestCase`` classes but not
on plain classes. ``nose`` supports these methods also on plain
classes but pytest deliberately does not. As nose and pytest already
classes but pytest deliberately does not. As nose and pytest already
both support ``setup_class, teardown_class, setup_method, teardown_method``
it doesn't seem useful to duplicate the unittest-API like nose does.
If you however rather think pytest should support the unittest-spelling on
@@ -44,9 +45,9 @@ Unsupported idioms / known issues
``tests.test_mod``) but different file system paths
(e.g. ``tests/test_mode.py`` and ``other/tests/test_mode.py``)
by extending sys.path/import semantics. pytest does not do that
but there is discussion in `issue268 <https://bitbucket.org/hpk42/pytest/issue/268>`_ for adding some support. Note that
but there is discussion in `issue268 <https://bitbucket.org/hpk42/pytest/issue/268>`_ for adding some support. Note that
`nose2 choose to avoid this sys.path/import hackery <https://nose2.readthedocs.org/en/latest/differences.html#test-discovery-and-loading>`_.
- nose-style doctests are not collected and executed correctly,
also doctest fixtures don't work.

View File

@@ -15,10 +15,10 @@ pytest supports test parametrization in several well-integrated ways:
at the level of fixture functions <fixture-parametrize>`.
* `@pytest.mark.parametrize`_ allows to define parametrization at the
function or class level, provides multiple argument/fixture sets
function or class level, provides multiple argument/fixture sets
for a particular test function or class.
* `pytest_generate_tests`_ enables implementing your own custom
* `pytest_generate_tests`_ enables implementing your own custom
dynamic parametrization scheme or extensions.
.. _parametrizemark:
@@ -47,13 +47,13 @@ to an expected output::
def test_eval(input, expected):
assert eval(input) == expected
Here, the ``@parametrize`` decorator defines three different ``(input,output)``
tuples so that that the ``test_eval`` function will run three times using
Here, the ``@parametrize`` decorator defines three different ``(input,expected)``
tuples so that the ``test_eval`` function will run three times using
them in turn::
$ py.test
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 3 items
test_expectation.py ..F
@@ -100,7 +100,7 @@ Let's run this::
$ py.test
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 3 items
test_expectation.py ..x
@@ -114,8 +114,8 @@ shows up as an "xfailed (expected to fail)" test.
In versions prior to 2.4 one needed to specify the argument
names as a tuple. This remains valid but the simpler ``"name1,name2,..."``
comma-separated-string syntax is now advertised fist because
it's easier to write, produces less line noise.
comma-separated-string syntax is now advertised first because
it's easier to write and produces less line noise.
.. _`pytest_generate_tests`:
@@ -124,14 +124,14 @@ Basic ``pytest_generate_tests`` example
Sometimes you may want to implement your own parametrization scheme
or implement some dynamism for determining the parameters or scope
of a fixture. For this, you can use the ``pytest_generate_tests`` hook
of a fixture. For this, you can use the ``pytest_generate_tests`` hook
which is called when collecting a test function. Through the passed in
`metafunc` object you can inspect the requesting test context and, most
importantly, you can call ``metafunc.parametrize()`` to cause
parametrization.
parametrization.
For example, let's say we want to run a test taking string inputs which
we want to set via a new py.test command line option. Let's first write
we want to set via a new ``pytest`` command line option. Let's first write
a simple test accepting a ``stringinput`` fixture function argument::
# content of test_strings.py
@@ -139,7 +139,7 @@ a simple test accepting a ``stringinput`` fixture function argument::
def test_valid_string(stringinput):
assert stringinput.isalpha()
Now we add a ``conftest.py`` file containing the addition of a
Now we add a ``conftest.py`` file containing the addition of a
command line option and the parametrization of our test function::
# content of conftest.py
@@ -150,7 +150,7 @@ command line option and the parametrization of our test function::
def pytest_generate_tests(metafunc):
if 'stringinput' in metafunc.fixturenames:
metafunc.parametrize("stringinput",
metafunc.parametrize("stringinput",
metafunc.config.option.stringinput)
If we now pass two stringinput values, our test will run twice::
@@ -170,22 +170,22 @@ Let's also run with a stringinput that will lead to a failing test::
def test_valid_string(stringinput):
> assert stringinput.isalpha()
E assert <built-in method isalpha of str object at 0x2b72934ca198>()
E + where <built-in method isalpha of str object at 0x2b72934ca198> = '!'.isalpha
E assert <built-in method isalpha of str object at 0x2ab7463a6b58>()
E + where <built-in method isalpha of str object at 0x2ab7463a6b58> = '!'.isalpha
test_strings.py:3: AssertionError
1 failed in 0.01 seconds
As expected our test function fails.
As expected our test function fails.
If you don't specify a stringinput it will be skipped because
``metafunc.parametrize()`` will be called with an empty parameter
listlist::
$ py.test -q -rs test_strings.py
$ py.test -q -rs test_strings.py
s
========================= short test summary info ==========================
SKIP [1] /home/hpk/p/pytest/.tox/regen/local/lib/python2.7/site-packages/_pytest/python.py:1094: got empty parameter set, function test_valid_string at /tmp/doc-exec-24/test_strings.py:1
SKIP [1] /home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/_pytest/python.py:1139: got empty parameter set, function test_valid_string at /tmp/doc-exec-195/test_strings.py:1
1 skipped in 0.01 seconds
For further examples, you might want to look at :ref:`more

View File

@@ -3,9 +3,9 @@
Working with plugins and conftest files
=============================================
py.test implements all aspects of configuration, collection, running and reporting by calling `well specified hooks`_. Virtually any Python module can be registered as a plugin. It can implement any number of hook functions (usually two or three) which all have a ``pytest_`` prefix, making hook functions easy to distinguish and find. There are three basic location types:
``pytest`` implements all aspects of configuration, collection, running and reporting by calling `well specified hooks`_. Virtually any Python module can be registered as a plugin. It can implement any number of hook functions (usually two or three) which all have a ``pytest_`` prefix, making hook functions easy to distinguish and find. There are three basic location types:
* `builtin plugins`_: loaded from py.test's internal ``_pytest`` directory.
* `builtin plugins`_: loaded from pytest's internal ``_pytest`` directory.
* `external plugins`_: modules discovered through `setuptools entry points`_
* `conftest.py plugins`_: modules auto-discovered in test directories
@@ -63,8 +63,11 @@ tool, for example::
pip install pytest-NAME
pip uninstall pytest-NAME
If a plugin is installed, py.test automatically finds and integrates it,
there is no need to activate it. Here is a initial list of known plugins:
If a plugin is installed, ``pytest`` automatically finds and integrates it,
there is no need to activate it. We have a :doc:`page listing
all 3rd party plugins and their status against the latest py.test version
<plugins_index/index>` and here is a little annotated list
for some popular plugins:
.. _`django`: https://www.djangoproject.com/
@@ -84,14 +87,14 @@ there is no need to activate it. Here is a initial list of known plugins:
* `pytest-xdist <http://pypi.python.org/pypi/pytest-xdist>`_:
to distribute tests to CPUs and remote hosts, to run in boxed
mode which allows to survive segmentation faults, to run in
looponfailing mode, automatically re-running failing tests
looponfailing mode, automatically re-running failing tests
on file changes, see also :ref:`xdist`
* `pytest-instafail <http://pypi.python.org/pypi/pytest-instafail>`_:
to report failures while the test run is happening.
* `pytest-bdd <http://pypi.python.org/pypi/pytest-bdd>`_ and
`pytest-konira <http://pypi.python.org/pypi/pytest-konira>`_
`pytest-konira <http://pypi.python.org/pypi/pytest-konira>`_
to write tests using behaviour-driven testing.
* `pytest-timeout <http://pypi.python.org/pypi/pytest-timeout>`_:
@@ -107,7 +110,11 @@ there is no need to activate it. Here is a initial list of known plugins:
* `oejskit <http://pypi.python.org/pypi/oejskit>`_:
a plugin to run javascript unittests in life browsers
You may discover more plugins through a `pytest- pypi.python.org search`_.
To see a complete list of all plugins with their latest testing
status against different py.test and Python versions, please visit
`pytest-plugs <http://pytest-plugs.herokuapp.com/>`_.
You may also discover more plugins through a `pytest- pypi.python.org search`_.
.. _`available installable plugins`:
.. _`pytest- pypi.python.org search`: http://pypi.python.org/pypi?%3Aaction=search&term=pytest-&submit=search
@@ -122,7 +129,7 @@ If you want to write a plugin, there are many real-life examples
you can copy from:
* a custom collection example plugin: :ref:`yaml plugin`
* around 20 `builtin plugins`_ which provide py.test's own functionality
* around 20 `builtin plugins`_ which provide pytest's own functionality
* many `external plugins`_ providing additional features
All of these plugins implement the documented `well specified hooks`_
@@ -135,10 +142,10 @@ Making your plugin installable by others
If you want to make your plugin externally available, you
may define a so-called entry point for your distribution so
that ``py.test`` finds your plugin module. Entry points are
that ``pytest`` finds your plugin module. Entry points are
a feature that is provided by `setuptools`_ or `Distribute`_.
py.test looks up the ``pytest11`` entrypoint to discover its
plugins and you can thus make your plugin available by definig
pytest looks up the ``pytest11`` entrypoint to discover its
plugins and you can thus make your plugin available by defining
it in your setuptools/distribute-based setup-invocation:
.. sourcecode:: python
@@ -150,7 +157,7 @@ it in your setuptools/distribute-based setup-invocation:
name="myproject",
packages = ['myproject']
# the following makes a plugin available to py.test
# the following makes a plugin available to pytest
entry_points = {
'pytest11': [
'name_of_plugin = myproject.pluginmodule',
@@ -158,7 +165,7 @@ it in your setuptools/distribute-based setup-invocation:
},
)
If a package is installed this way, py.test will load
If a package is installed this way, ``pytest`` will load
``myproject.pluginmodule`` as a plugin which can define
`well specified hooks`_.
@@ -167,7 +174,7 @@ If a package is installed this way, py.test will load
Plugin discovery order at tool startup
--------------------------------------------
py.test loads plugin modules at tool startup in the following way:
``pytest`` loads plugin modules at tool startup in the following way:
* by loading all builtin plugins
@@ -177,9 +184,15 @@ py.test loads plugin modules at tool startup in the following way:
and loading the specified plugin before actual command line parsing.
* by loading all :file:`conftest.py` files as inferred by the command line
invocation (test files and all of its *parent* directories).
Note that ``conftest.py`` files from *sub* directories are by default
not loaded at tool startup.
invocation:
- if no test paths are specified use current dir as a test path
- if exists, load ``conftest.py`` and ``test*/conftest.py`` relative
to the directory part of the first test path.
Note that pytest does not find ``conftest.py`` files in deeper nested
sub directories at tool startup. It is usually a good idea to keep
your conftest.py file in the top level test or project root directory.
* by recursively loading all plugins specified by the
``pytest_plugins`` variable in ``conftest.py`` files
@@ -197,7 +210,7 @@ will be loaded as well. You can also use dotted path like this::
pytest_plugins = "myapp.testsupport.myplugin"
which will import the specified module as a py.test plugin.
which will import the specified module as a ``pytest`` plugin.
Accessing another plugin by name
@@ -243,7 +256,7 @@ how to obtain the name of a plugin.
.. _`builtin plugins`:
py.test default plugin reference
pytest default plugin reference
====================================
@@ -277,14 +290,14 @@ in the `pytest repository <http://bitbucket.org/hpk42/pytest/>`_.
.. _`well specified hooks`:
py.test hook reference
pytest hook reference
====================================
Hook specification and validation
-----------------------------------------
py.test calls hook functions to implement initialization, running,
test execution and reporting. When py.test loads a plugin it validates
``pytest`` calls hook functions to implement initialization, running,
test execution and reporting. When ``pytest`` loads a plugin it validates
that each hook function conforms to its respective hook specification.
Each hook function name and its argument names need to match a hook
specification. However, a hook function may accept *fewer* parameters
@@ -296,6 +309,7 @@ Initialization, command line and configuration hooks
.. currentmodule:: _pytest.hookspec
.. autofunction:: pytest_load_initial_conftests
.. autofunction:: pytest_cmdline_preparse
.. autofunction:: pytest_cmdline_parse
.. autofunction:: pytest_namespace
@@ -307,7 +321,7 @@ Initialization, command line and configuration hooks
Generic "runtest" hooks
------------------------------
All all runtest related hooks receive a :py:class:`pytest.Item` object.
All runtest related hooks receive a :py:class:`pytest.Item` object.
.. autofunction:: pytest_runtest_protocol
.. autofunction:: pytest_runtest_setup
@@ -327,7 +341,7 @@ the reporting hook to print information about a test run.
Collection hooks
------------------------------
py.test calls the following hooks for collecting files and directories:
``pytest`` calls the following hooks for collecting files and directories:
.. autofunction:: pytest_ignore_collect
.. autofunction:: pytest_collect_directory

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

View File

@@ -0,0 +1,165 @@
.. _plugins_index:
List of Third-Party Plugins
===========================
The table below contains a listing of plugins found in PyPI and
their status when tested using py.test **2.6.2.dev1** and python 2.7 and
3.3.
A complete listing can also be found at
`pytest-plugs <http://pytest-plugs.herokuapp.com/>`_, which contains tests
status against other py.test releases.
========================================================================================== ================================================================================================================= ================================================================================================================= ======================================================================================== =============================================================================================================================================
Name Py27 Py34 Repo Summary
========================================================================================== ================================================================================================================= ================================================================================================================= ======================================================================================== =============================================================================================================================================
`pytest-allure-adaptor-1.4.0 <http://pypi.python.org/pypi/pytest-allure-adaptor>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-allure-adaptor-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-allure-adaptor-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Plugin for py.test to generate allure xml reports
:target: http://pytest-plugs.herokuapp.com/output/pytest-allure-adaptor-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-allure-adaptor-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/allure-framework/allure-python
`pytest-bdd-2.3.1 <http://pypi.python.org/pypi/pytest-bdd>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bdd-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bdd-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png BDD for pytest
:target: http://pytest-plugs.herokuapp.com/output/pytest-bdd-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-bdd-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/olegpidsadnyi/pytest-bdd
`pytest-beds-0.0.1 <http://pypi.python.org/pypi/pytest-beds>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-beds-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-beds-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Fixtures for testing Google Appengine (GAE) apps
:target: http://pytest-plugs.herokuapp.com/output/pytest-beds-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-beds-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/kaste/pytest-beds
`pytest-bench-0.3.0 <http://pypi.python.org/pypi/pytest-bench>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bench-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bench-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Benchmark utility that plugs into pytest.
:target: http://pytest-plugs.herokuapp.com/output/pytest-bench-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-bench-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/concordusapps/pytest-bench
`pytest-blockage-0.1 <http://pypi.python.org/pypi/pytest-blockage>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-blockage-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-blockage-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Disable network requests during a test run.
:target: http://pytest-plugs.herokuapp.com/output/pytest-blockage-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-blockage-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/rob-b/pytest-blockage
`pytest-browsermob-proxy-0.1 <http://pypi.python.org/pypi/pytest-browsermob-proxy>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-browsermob-proxy-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-browsermob-proxy-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png BrowserMob proxy plugin for py.test.
:target: http://pytest-plugs.herokuapp.com/output/pytest-browsermob-proxy-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-browsermob-proxy-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/davehunt/pytest-browsermob-proxy
`pytest-bugzilla-0.2 <http://pypi.python.org/pypi/pytest-bugzilla>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bugzilla-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bugzilla-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test bugzilla integration plugin
:target: http://pytest-plugs.herokuapp.com/output/pytest-bugzilla-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-bugzilla-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/nibrahim/pytest_bugzilla
`pytest-cache-1.0 <http://pypi.python.org/pypi/pytest-cache>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cache-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cache-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png pytest plugin with mechanisms for caching across test runs
:target: http://pytest-plugs.herokuapp.com/output/pytest-cache-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-cache-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/hpk42/pytest-cache/
`pytest-capturelog-0.7 <http://pypi.python.org/pypi/pytest-capturelog>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-capturelog-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-capturelog-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png py.test plugin to capture log messages
:target: http://pytest-plugs.herokuapp.com/output/pytest-capturelog-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-capturelog-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/memedough/pytest-capturelog/overview
`pytest-codecheckers-0.2 <http://pypi.python.org/pypi/pytest-codecheckers>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-codecheckers-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-codecheckers-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png pytest plugin to add source code sanity checks (pep8 and friends)
:target: http://pytest-plugs.herokuapp.com/output/pytest-codecheckers-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-codecheckers-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/RonnyPfannschmidt/pytest-codecheckers/
`pytest-config-0.0.10 <http://pypi.python.org/pypi/pytest-config>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-config-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-config-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Base configurations and utilities for developing your Python project test suite with pytest.
:target: http://pytest-plugs.herokuapp.com/output/pytest-config-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-config-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/buzzfeed/pytest_config
`pytest-contextfixture-0.1.1 <http://pypi.python.org/pypi/pytest-contextfixture>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-contextfixture-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-contextfixture-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Define pytest fixtures as context managers.
:target: http://pytest-plugs.herokuapp.com/output/pytest-contextfixture-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-contextfixture-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/pelme/pytest-contextfixture/
`pytest-couchdbkit-0.5.1 <http://pypi.python.org/pypi/pytest-couchdbkit>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-couchdbkit-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-couchdbkit-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png py.test extension for per-test couchdb databases using couchdbkit
:target: http://pytest-plugs.herokuapp.com/output/pytest-couchdbkit-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-couchdbkit-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/RonnyPfannschmidt/pytest-couchdbkit
`pytest-cov-1.8.0 <http://pypi.python.org/pypi/pytest-cov>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cov-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cov-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test plugin for coverage reporting with support for both centralised and distributed testing, including subprocesses and multiprocessing
:target: http://pytest-plugs.herokuapp.com/output/pytest-cov-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-cov-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/schlamar/pytest-cov
`pytest-cpp-0.3.0 <http://pypi.python.org/pypi/pytest-cpp>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cpp-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cpp-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Use pytest's runner to discover and execute C++ tests
:target: http://pytest-plugs.herokuapp.com/output/pytest-cpp-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-cpp-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/nicoddemus/pytest-cpp
`pytest-dbfixtures-0.5.1 <http://pypi.python.org/pypi/pytest-dbfixtures>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-dbfixtures-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-dbfixtures-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Databases fixtures plugin for py.test.
:target: http://pytest-plugs.herokuapp.com/output/pytest-dbfixtures-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-dbfixtures-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/ClearcodeHQ/pytest-dbfixtures
`pytest-dbus-notification-1.0.1 <http://pypi.python.org/pypi/pytest-dbus-notification>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-dbus-notification-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-dbus-notification-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png D-BUS notifications for pytest results.
:target: http://pytest-plugs.herokuapp.com/output/pytest-dbus-notification-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-dbus-notification-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/bmathieu33/pytest-dbus-notification
`pytest-diffeo-0.1.8.dev1 <http://pypi.python.org/pypi/pytest-diffeo>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-diffeo-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-diffeo-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Common py.test support for Diffeo packages
:target: http://pytest-plugs.herokuapp.com/output/pytest-diffeo-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-diffeo-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/diffeo/pytest-diffeo
`pytest-django-2.6.2 <http://pypi.python.org/pypi/pytest-django>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-latest?py=py34&pytest=2.6.2.dev1 `http://pytest-django.readthedocs.org/ <http://pytest-django.readthedocs.org/>`_ A Django plugin for py.test.
:target: http://pytest-plugs.herokuapp.com/output/pytest-django-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-django-latest?py=py34&pytest=2.6.2.dev1
`pytest-django-haystack-0.1.1 <http://pypi.python.org/pypi/pytest-django-haystack>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-haystack-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-haystack-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Cleanup your Haystack indexes between tests
:target: http://pytest-plugs.herokuapp.com/output/pytest-django-haystack-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-django-haystack-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/rouge8/pytest-django-haystack
`pytest-django-lite-0.1.1 <http://pypi.python.org/pypi/pytest-django-lite>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-lite-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-lite-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png The bare minimum to integrate py.test with Django.
:target: http://pytest-plugs.herokuapp.com/output/pytest-django-lite-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-django-lite-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/dcramer/pytest-django-lite
`pytest-echo-1.3 <http://pypi.python.org/pypi/pytest-echo>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-echo-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-echo-latest?py=py34&pytest=2.6.2.dev1 `http://pypi.python.org/pypi/pytest-echo/ <http://pypi.python.org/pypi/pytest-echo/>`_ pytest plugin with mechanisms for echoing environment variables, package version and generic attributes
:target: http://pytest-plugs.herokuapp.com/output/pytest-echo-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-echo-latest?py=py34&pytest=2.6.2.dev1
`pytest-eradicate-0.0.2 <http://pypi.python.org/pypi/pytest-eradicate>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-eradicate-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-eradicate-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest plugin to check for commented out code
:target: http://pytest-plugs.herokuapp.com/output/pytest-eradicate-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-eradicate-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/spil-johan/pytest-eradicate
`pytest-figleaf-1.0 <http://pypi.python.org/pypi/pytest-figleaf>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-figleaf-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-figleaf-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png py.test figleaf coverage plugin
:target: http://pytest-plugs.herokuapp.com/output/pytest-figleaf-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-figleaf-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/hpk42/pytest-figleaf
`pytest-fixture-tools-1.0.0 <http://pypi.python.org/pypi/pytest-fixture-tools>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-fixture-tools-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-fixture-tools-latest?py=py34&pytest=2.6.2.dev1 ? Plugin for pytest which provides tools for fixtures
:target: http://pytest-plugs.herokuapp.com/output/pytest-fixture-tools-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-fixture-tools-latest?py=py34&pytest=2.6.2.dev1
`pytest-flakes-0.2 <http://pypi.python.org/pypi/pytest-flakes>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-flakes-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-flakes-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest plugin to check source code with pyflakes
:target: http://pytest-plugs.herokuapp.com/output/pytest-flakes-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-flakes-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/fschulze/pytest-flakes
`pytest-greendots-0.3 <http://pypi.python.org/pypi/pytest-greendots>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-greendots-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-greendots-latest?py=py34&pytest=2.6.2.dev1 ? Green progress dots
:target: http://pytest-plugs.herokuapp.com/output/pytest-greendots-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-greendots-latest?py=py34&pytest=2.6.2.dev1
`pytest-growl-0.2 <http://pypi.python.org/pypi/pytest-growl>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-growl-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-growl-latest?py=py34&pytest=2.6.2.dev1 ? Growl notifications for pytest results.
:target: http://pytest-plugs.herokuapp.com/output/pytest-growl-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-growl-latest?py=py34&pytest=2.6.2.dev1
`pytest-httpbin-0.0.2 <http://pypi.python.org/pypi/pytest-httpbin>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-httpbin-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-httpbin-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Easily test your HTTP library against a local copy of httpbin
:target: http://pytest-plugs.herokuapp.com/output/pytest-httpbin-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-httpbin-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/kevin1024/pytest-httpbin
`pytest-httpretty-0.2.0 <http://pypi.python.org/pypi/pytest-httpretty>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-httpretty-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-httpretty-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png A thin wrapper of HTTPretty for pytest
:target: http://pytest-plugs.herokuapp.com/output/pytest-httpretty-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-httpretty-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/papaeye/pytest-httpretty
`pytest-incremental-0.3.0 <http://pypi.python.org/pypi/pytest-incremental>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-incremental-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-incremental-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png an incremental test runner (pytest plugin)
:target: http://pytest-plugs.herokuapp.com/output/pytest-incremental-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-incremental-latest?py=py34&pytest=2.6.2.dev1 :target: https://bitbucket.org/schettino72/pytest-incremental
`pytest-instafail-0.2.0 <http://pypi.python.org/pypi/pytest-instafail>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-instafail-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-instafail-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test plugin to show failures instantly
:target: http://pytest-plugs.herokuapp.com/output/pytest-instafail-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-instafail-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/jpvanhal/pytest-instafail
`pytest-ipdb-0.1-prerelease <http://pypi.python.org/pypi/pytest-ipdb>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-ipdb-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-ipdb-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png A py.test plug-in to enable drop to ipdb debugger on test failure.
:target: http://pytest-plugs.herokuapp.com/output/pytest-ipdb-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-ipdb-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/mverteuil/pytest-ipdb
`pytest-jira-0.01 <http://pypi.python.org/pypi/pytest-jira>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-jira-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-jira-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test JIRA integration plugin, using markers
:target: http://pytest-plugs.herokuapp.com/output/pytest-jira-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-jira-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/jlaska/pytest_jira
`pytest-knows-0.1.5 <http://pypi.python.org/pypi/pytest-knows>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-knows-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-knows-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png A pytest plugin that can automaticly skip test case based on dependence info calculated by trace
:target: http://pytest-plugs.herokuapp.com/output/pytest-knows-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-knows-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/mapix/ptknows
`pytest-konira-0.2 <http://pypi.python.org/pypi/pytest-konira>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-konira-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-konira-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Run Konira DSL tests with py.test
:target: http://pytest-plugs.herokuapp.com/output/pytest-konira-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-konira-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/alfredodeza/pytest-konira
`pytest-localserver-0.3.2 <http://pypi.python.org/pypi/pytest-localserver>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-localserver-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-localserver-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png py.test plugin to test server connections locally.
:target: http://pytest-plugs.herokuapp.com/output/pytest-localserver-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-localserver-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/basti/pytest-localserver/
`pytest-marker-bugzilla-0.06 <http://pypi.python.org/pypi/pytest-marker-bugzilla>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marker-bugzilla-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marker-bugzilla-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test bugzilla integration plugin, using markers
:target: http://pytest-plugs.herokuapp.com/output/pytest-marker-bugzilla-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-marker-bugzilla-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/eanxgeek/pytest_marker_bugzilla
`pytest-markfiltration-0.8 <http://pypi.python.org/pypi/pytest-markfiltration>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-markfiltration-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-markfiltration-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png UNKNOWN
:target: http://pytest-plugs.herokuapp.com/output/pytest-markfiltration-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-markfiltration-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/adamgoucher/pytest-markfiltration
`pytest-marks-0.4 <http://pypi.python.org/pypi/pytest-marks>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marks-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marks-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png UNKNOWN
:target: http://pytest-plugs.herokuapp.com/output/pytest-marks-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-marks-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/adamgoucher/pytest-marks
`pytest-mock-0.3.0 <http://pypi.python.org/pypi/pytest-mock>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-mock-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-mock-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Thin-wrapper around the mock package for easier use with py.test
:target: http://pytest-plugs.herokuapp.com/output/pytest-mock-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-mock-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/nicoddemus/pytest-mock/
`pytest-monkeyplus-1.1.0 <http://pypi.python.org/pypi/pytest-monkeyplus>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-monkeyplus-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-monkeyplus-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png pytest's monkeypatch subclass with extra functionalities
:target: http://pytest-plugs.herokuapp.com/output/pytest-monkeyplus-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-monkeyplus-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/hsoft/pytest-monkeyplus/
`pytest-mozwebqa-1.1.1 <http://pypi.python.org/pypi/pytest-mozwebqa>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-mozwebqa-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-mozwebqa-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Mozilla WebQA plugin for py.test.
:target: http://pytest-plugs.herokuapp.com/output/pytest-mozwebqa-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-mozwebqa-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/davehunt/pytest-mozwebqa
`pytest-oerp-0.2.0 <http://pypi.python.org/pypi/pytest-oerp>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-oerp-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-oerp-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest plugin to test OpenERP modules
:target: http://pytest-plugs.herokuapp.com/output/pytest-oerp-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-oerp-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/santagada/pytest-oerp/
`pytest-ordering-0.3 <http://pypi.python.org/pypi/pytest-ordering>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-ordering-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-ordering-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest plugin to run your tests in a specific order
:target: http://pytest-plugs.herokuapp.com/output/pytest-ordering-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-ordering-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/ftobia/pytest-ordering
`pytest-osxnotify-0.1.4 <http://pypi.python.org/pypi/pytest-osxnotify>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-osxnotify-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-osxnotify-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png OS X notifications for py.test results.
:target: http://pytest-plugs.herokuapp.com/output/pytest-osxnotify-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-osxnotify-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/dbader/pytest-osxnotify
`pytest-paste-config-0.1 <http://pypi.python.org/pypi/pytest-paste-config>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-paste-config-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-paste-config-latest?py=py34&pytest=2.6.2.dev1 ? Allow setting the path to a paste config file
:target: http://pytest-plugs.herokuapp.com/output/pytest-paste-config-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-paste-config-latest?py=py34&pytest=2.6.2.dev1
`pytest-pep8-1.0.6 <http://pypi.python.org/pypi/pytest-pep8>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pep8-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pep8-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png pytest plugin to check PEP8 requirements
:target: http://pytest-plugs.herokuapp.com/output/pytest-pep8-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-pep8-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/hpk42/pytest-pep8/
`pytest-pipeline-0.1.0 <http://pypi.python.org/pypi/pytest-pipeline>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pipeline-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pipeline-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Pytest plugin for functional testing of data analysis pipelines
:target: http://pytest-plugs.herokuapp.com/output/pytest-pipeline-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-pipeline-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/bow/pytest_pipeline
`pytest-poo-0.2 <http://pypi.python.org/pypi/pytest-poo>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-poo-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-poo-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Visualize your crappy tests
:target: http://pytest-plugs.herokuapp.com/output/pytest-poo-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-poo-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/pelme/pytest-poo
`pytest-pycharm-0.1.0 <http://pypi.python.org/pypi/pytest-pycharm>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pycharm-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pycharm-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Plugin for py.test to enter PyCharm debugger on uncaught exceptions
:target: http://pytest-plugs.herokuapp.com/output/pytest-pycharm-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-pycharm-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/jlubcke/pytest-pycharm
`pytest-pydev-0.1 <http://pypi.python.org/pypi/pytest-pydev>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pydev-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pydev-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png py.test plugin to connect to a remote debug server with PyDev or PyCharm.
:target: http://pytest-plugs.herokuapp.com/output/pytest-pydev-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-pydev-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/basti/pytest-pydev/
`pytest-pythonpath-0.3 <http://pypi.python.org/pypi/pytest-pythonpath>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pythonpath-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pythonpath-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest plugin for adding to the PYTHONPATH from command line or configs.
:target: http://pytest-plugs.herokuapp.com/output/pytest-pythonpath-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-pythonpath-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/bigsassy/pytest-pythonpath
`pytest-qt-1.2.0 <http://pypi.python.org/pypi/pytest-qt>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-qt-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-qt-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest support for PyQt and PySide applications
:target: http://pytest-plugs.herokuapp.com/output/pytest-qt-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-qt-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/nicoddemus/pytest-qt
`pytest-quickcheck-0.8 <http://pypi.python.org/pypi/pytest-quickcheck>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-quickcheck-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-quickcheck-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png pytest plugin to generate random data inspired by QuickCheck
:target: http://pytest-plugs.herokuapp.com/output/pytest-quickcheck-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-quickcheck-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/t2y/pytest-quickcheck/
`pytest-rage-0.1 <http://pypi.python.org/pypi/pytest-rage>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rage-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rage-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest plugin to implement PEP712
:target: http://pytest-plugs.herokuapp.com/output/pytest-rage-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-rage-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/santagada/pytest-rage/
`pytest-raisesregexp-1.0 <http://pypi.python.org/pypi/pytest-raisesregexp>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-raisesregexp-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-raisesregexp-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Simple pytest plugin to look for regex in Exceptions
:target: http://pytest-plugs.herokuapp.com/output/pytest-raisesregexp-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-raisesregexp-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/Walkman/pytest_raisesregexp
`pytest-random-0.02 <http://pypi.python.org/pypi/pytest-random>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-random-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-random-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test plugin to randomize tests
:target: http://pytest-plugs.herokuapp.com/output/pytest-random-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-random-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/klrmn/pytest-random
`pytest-rerunfailures-0.05 <http://pypi.python.org/pypi/pytest-rerunfailures>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rerunfailures-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rerunfailures-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test plugin to re-run tests to eliminate flakey failures
:target: http://pytest-plugs.herokuapp.com/output/pytest-rerunfailures-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-rerunfailures-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/klrmn/pytest-rerunfailures
`pytest-runfailed-0.3 <http://pypi.python.org/pypi/pytest-runfailed>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runfailed-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runfailed-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png implement a --failed option for pytest
:target: http://pytest-plugs.herokuapp.com/output/pytest-runfailed-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-runfailed-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/dmerejkowsky/pytest-runfailed
`pytest-runner-2.1 <http://pypi.python.org/pypi/pytest-runner>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runner-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runner-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png UNKNOWN
:target: http://pytest-plugs.herokuapp.com/output/pytest-runner-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-runner-latest?py=py34&pytest=2.6.2.dev1 :target: https://bitbucket.org/jaraco/pytest-runner
`pytest-sftpserver-1.0.2 <http://pypi.python.org/pypi/pytest-sftpserver>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-sftpserver-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-sftpserver-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test plugin to locally test sftp server connections.
:target: http://pytest-plugs.herokuapp.com/output/pytest-sftpserver-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-sftpserver-latest?py=py34&pytest=2.6.2.dev1 :target: http://github.com/ulope/pytest-sftpserver/
`pytest-spec-0.2.22 <http://pypi.python.org/pypi/pytest-spec>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-spec-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-spec-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png pytest plugin to display test execution output like a SPECIFICATION
:target: http://pytest-plugs.herokuapp.com/output/pytest-spec-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-spec-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/pchomik/pytest-spec
`pytest-splinter-1.0.3 <http://pypi.python.org/pypi/pytest-splinter>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-splinter-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-splinter-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Splinter subplugin for Pytest BDD plugin
:target: http://pytest-plugs.herokuapp.com/output/pytest-splinter-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-splinter-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/paylogic/pytest-splinter
`pytest-stepwise-0.2 <http://pypi.python.org/pypi/pytest-stepwise>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-stepwise-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-stepwise-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png Run a test suite one failing test at a time.
:target: http://pytest-plugs.herokuapp.com/output/pytest-stepwise-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-stepwise-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/nip3o/pytest-stepwise
`pytest-sugar-0.3.4 <http://pypi.python.org/pypi/pytest-sugar>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-sugar-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-sugar-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png py.test is a plugin for py.test that changes the default look and feel of py.test (e.g. progressbar, show tests that fail instantly).
:target: http://pytest-plugs.herokuapp.com/output/pytest-sugar-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-sugar-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/Frozenball/pytest-sugar
`pytest-timeout-0.4 <http://pypi.python.org/pypi/pytest-timeout>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-timeout-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-timeout-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png py.test plugin to abort hanging tests
:target: http://pytest-plugs.herokuapp.com/output/pytest-timeout-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-timeout-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/flub/pytest-timeout/
`pytest-twisted-1.5 <http://pypi.python.org/pypi/pytest-twisted>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-twisted-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-twisted-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png A twisted plugin for py.test.
:target: http://pytest-plugs.herokuapp.com/output/pytest-twisted-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-twisted-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/schmir/pytest-twisted
`pytest-xdist-1.10 <http://pypi.python.org/pypi/pytest-xdist>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xdist-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xdist-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png py.test xdist plugin for distributed testing and loop-on-failing modes
:target: http://pytest-plugs.herokuapp.com/output/pytest-xdist-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-xdist-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/hpk42/pytest-xdist
`pytest-xprocess-0.8 <http://pypi.python.org/pypi/pytest-xprocess>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xprocess-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xprocess-latest?py=py34&pytest=2.6.2.dev1 .. image:: bitbucket.png pytest plugin to manage external processes across test runs
:target: http://pytest-plugs.herokuapp.com/output/pytest-xprocess-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-xprocess-latest?py=py34&pytest=2.6.2.dev1 :target: http://bitbucket.org/hpk42/pytest-xprocess/
`pytest-yamlwsgi-0.6 <http://pypi.python.org/pypi/pytest-yamlwsgi>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-yamlwsgi-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-yamlwsgi-latest?py=py34&pytest=2.6.2.dev1 ? Run tests against wsgi apps defined in yaml
:target: http://pytest-plugs.herokuapp.com/output/pytest-yamlwsgi-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-yamlwsgi-latest?py=py34&pytest=2.6.2.dev1
`pytest-zap-0.2 <http://pypi.python.org/pypi/pytest-zap>`_ .. image:: http://pytest-plugs.herokuapp.com/status/pytest-zap-latest?py=py27&pytest=2.6.2.dev1 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-zap-latest?py=py34&pytest=2.6.2.dev1 .. image:: github.png OWASP ZAP plugin for py.test.
:target: http://pytest-plugs.herokuapp.com/output/pytest-zap-latest?py=py27&pytest=2.6.2.dev1 :target: http://pytest-plugs.herokuapp.com/output/pytest-zap-latest?py=py34&pytest=2.6.2.dev1 :target: https://github.com/davehunt/pytest-zap
========================================================================================== ================================================================================================================= ================================================================================================================= ======================================================================================== =============================================================================================================================================
*(Updated on 2014-08-26)*

View File

@@ -1,9 +1,18 @@
'''
Script to generate the file `plugins_index.txt` with information about pytest plugins taken directly
from a live PyPI server.
"""
Script to generate the file `index.txt` with information about
pytest plugins taken directly from PyPI.
This will evolve to include test compatibility (pythons and pytest versions) information also.
'''
Usage:
python plugins_index.py
This command will update `index.txt` in the same directory found as this script.
This should be issued before every major documentation release to obtain latest
versions from PyPI.
Also includes plugin compatibility between different python and pytest versions,
obtained from http://pytest-plugs.herokuapp.com.
"""
from __future__ import print_function
from collections import namedtuple
import datetime
from distutils.version import LooseVersion
@@ -11,184 +20,273 @@ import itertools
from optparse import OptionParser
import os
import sys
import xmlrpclib
import pytest
#===================================================================================================
# iter_plugins
#===================================================================================================
def get_proxy(url):
"""
wrapper function to obtain a xmlrpc proxy, taking in account import
differences between python 2.X and 3.X
:param url: url to bind the proxy to
:return: a ServerProxy instance
"""
if sys.version_info < (3, 0):
from xmlrpclib import ServerProxy
else:
from xmlrpc.client import ServerProxy
return ServerProxy(url)
def iter_plugins(client, search='pytest-'):
'''
"""
Returns an iterator of (name, version) from PyPI.
:param client: xmlrpclib.ServerProxy
:param search: package names to search for
'''
for plug_data in client.search({'name' : search}):
:param client: ServerProxy
:param search: package names to search for
"""
for plug_data in client.search({'name': search}):
yield plug_data['name'], plug_data['version']
#===================================================================================================
# get_latest_versions
#===================================================================================================
def get_latest_versions(plugins):
'''
Returns an iterator of (name, version) from the given list of (name, version), but returning
only the latest version of the package. Uses distutils.LooseVersion to ensure compatibility
with PEP386.
'''
"""
Returns an iterator of (name, version) from the given list of (name,
version), but returning only the latest version of the package. Uses
distutils.LooseVersion to ensure compatibility with PEP386.
"""
plugins = [(name, LooseVersion(version)) for (name, version) in plugins]
for name, grouped_plugins in itertools.groupby(plugins, key=lambda x: x[0]):
name, loose_version = list(grouped_plugins)[-1]
yield name, str(loose_version)
#===================================================================================================
# obtain_plugins_table
#===================================================================================================
def obtain_plugins_table(plugins, client):
'''
Returns information to populate a table of plugins, their versions, authors, etc.
The returned information is a list of columns of `ColumnData` namedtuples(text, link). Link
can be None if the text for that column should not be linked to anything.
def obtain_plugins_table(plugins, client):
"""
Returns information to populate a table of plugins, their versions,
authors, etc.
The returned information is a list of columns of `ColumnData`
namedtuples(text, link). Link can be None if the text for that column
should not be linked to anything.
:param plugins: list of (name, version)
:param client: xmlrpclib.ServerProxy
'''
:param client: ServerProxy
"""
def get_repo_markup(repo):
"""
obtains appropriate markup for the given repository, as two lines
that should be output in the same table row. We use this to display an icon
for known repository hosts (github, etc), just a "?" char when
repository is not registered in pypi or a simple link otherwise.
"""
target = repo
if 'github.com' in repo:
image = 'github.png'
elif 'bitbucket.org' in repo:
image = 'bitbucket.png'
elif repo.lower() == 'unknown':
return '?', ''
else:
image = None
if image is not None:
image_markup = '.. image:: %s' % image
target_markup = ' :target: %s' % repo
pad_right = ('%-' + str(len(target_markup)) + 's')
return pad_right % image_markup, target_markup
else:
return ('`%s <%s>`_' % (target, target)), ''
def sanitize_summary(summary):
"""Make sure summaries don't break our table formatting.
"""
return summary.replace('\n', ' ')
rows = []
ColumnData = namedtuple('ColumnData', 'text link')
headers = ['Name', 'Author', 'Downloads', 'Python 2.7', 'Python 3.3', 'Summary']
headers = ['Name', 'Py27', 'Py34', 'Repo', 'Summary']
pytest_version = pytest.__version__
print '*** pytest-{} ***'.format(pytest_version)
repositories = obtain_override_repositories()
print('*** pytest-{0} ***'.format(pytest_version))
plugins = list(plugins)
for index, (package_name, version) in enumerate(plugins):
print package_name, version, '...',
print(package_name, version, '...', end='')
release_data = client.release_data(package_name, version)
download_count = release_data['downloads']['last_month']
image_url = '.. image:: http://pytest-plugs.herokuapp.com/status/{name}-{version}'.format(name=package_name,
version=version)
common_params = dict(
site='http://pytest-plugs.herokuapp.com',
name=package_name,
version=version)
repository = repositories.get(package_name, release_data['home_page'])
repo_markup_1, repo_markup_2 = get_repo_markup(repository)
# first row: name, images and simple links
url = '.. image:: {site}/status/{name}-latest'
image_url = url.format(**common_params)
image_url += '?py={py}&pytest={pytest}'
row = (
ColumnData(package_name + '-' + version, release_data['release_url']),
ColumnData(release_data['author'], release_data['author_email']),
ColumnData(str(download_count), None),
ColumnData(image_url.format(py='py27', pytest=pytest_version), None),
ColumnData(image_url.format(py='py33', pytest=pytest_version), None),
ColumnData(release_data['summary'], None),
ColumnData(package_name + "-" + version, release_data['package_url']),
ColumnData(image_url.format(py='py27', pytest=pytest_version),
None),
ColumnData(image_url.format(py='py34', pytest=pytest_version),
None),
ColumnData(
repo_markup_1,
None),
ColumnData(sanitize_summary(release_data['summary']), None),
)
assert len(row) == len(headers)
rows.append(row)
print 'OK (%d%%)' % ((index + 1) * 100 / len(plugins))
return headers, rows
# second row: links for images (they should be in their own line)
url = ' :target: {site}/output/{name}-latest'
output_url = url.format(**common_params)
output_url += '?py={py}&pytest={pytest}'
row = (
ColumnData('', None),
ColumnData(output_url.format(py='py27', pytest=pytest_version),
None),
ColumnData(output_url.format(py='py34', pytest=pytest_version),
None),
ColumnData(repo_markup_2, None),
ColumnData('', None),
)
assert len(row) == len(headers)
rows.append(row)
print('OK (%d%%)' % ((index + 1) * 100 / len(plugins)))
return headers, rows
def obtain_override_repositories():
"""
Used to override the "home_page" obtained from pypi to known
package repositories. Used when the author didn't fill the "home_page"
field in setup.py.
:return: dict of {package_name: repository_url}
"""
return {
'pytest-blockage': 'https://github.com/rob-b/pytest-blockage',
'pytest-konira': 'http://github.com/alfredodeza/pytest-konira',
'pytest-sugar': 'https://github.com/Frozenball/pytest-sugar',
}
#===================================================================================================
# generate_plugins_index_from_table
#===================================================================================================
def generate_plugins_index_from_table(filename, headers, rows):
'''
"""
Generates a RST file with the table data given.
:param filename: output filename
:param headers: see `obtain_plugins_table`
:param rows: see `obtain_plugins_table`
'''
# creates a list of rows, each being a str containing appropriate column text and link
"""
# creates a list of rows, each being a str containing appropriate column
# text and link
table_texts = []
for row in rows:
column_texts = []
for i, col_data in enumerate(row):
text = '`%s <%s>`_' % (col_data.text, col_data.link) if col_data.link else col_data.text
for i, col_data in enumerate(row):
text = '`%s <%s>`_' % (
col_data.text,
col_data.link) if col_data.link else col_data.text
column_texts.append(text)
table_texts.append(column_texts)
# compute max length of each column so we can build the rst table
column_lengths = [len(x) for x in headers]
for column_texts in table_texts:
for i, row_text in enumerate(column_texts):
column_lengths[i] = max(column_lengths[i], len(row_text) + 2)
def get_row_limiter(char):
return ' '.join(char * length for length in column_lengths)
with file(filename, 'w') as f:
# write welcome
print >> f, '.. _plugins_index:'
print >> f
print >> f, 'List of Third-Party Plugins'
print >> f, '==========================='
print >> f
# table
print >> f, get_row_limiter('=')
for i, header in enumerate(headers):
print >> f, '{:^{fill}}'.format(header, fill=column_lengths[i]),
print >> f
print >> f, get_row_limiter('=')
with open(filename, 'w') as f:
# header
header_text = HEADER.format(pytest_version=pytest.__version__)
print(header_text, file=f)
print(file=f)
# table
print(get_row_limiter('='), file=f)
formatted_headers = [
'{0:^{fill}}'.format(header, fill=column_lengths[i])
for i, header in enumerate(headers)]
print(*formatted_headers, file=f)
print(get_row_limiter('='), file=f)
for column_texts in table_texts:
for i, row_text in enumerate(column_texts):
print >> f, '{:^{fill}}'.format(row_text, fill=column_lengths[i]),
print >> f
print >> f
print >> f, get_row_limiter('=')
print >> f
print >> f, '*(Downloads are given from last month only)*'
print >> f
print >> f, '*(Updated on %s)*' % _get_today_as_str()
#===================================================================================================
# _get_today_as_str
#===================================================================================================
def _get_today_as_str():
'''
internal. only exists so we can patch it in testing.
'''
return datetime.date.today().strftime('%Y-%m-%d')
formatted_rows = [
'{0:^{fill}}'.format(row_text, fill=column_lengths[i])
for i, row_text in enumerate(column_texts)
]
print(*formatted_rows, file=f)
print(file=f)
print(get_row_limiter('='), file=f)
print(file=f)
today = datetime.date.today().strftime('%Y-%m-%d')
print('*(Updated on %s)*' % today, file=f)
#===================================================================================================
# generate_plugins_index
#===================================================================================================
def generate_plugins_index(client, filename):
'''
Generates an RST file with a table of the latest pytest plugins found in PyPI.
:param client: xmlrpclib.ServerProxy
"""
Generates an RST file with a table of the latest pytest plugins found in
PyPI.
:param client: ServerProxy
:param filename: output filename
'''
"""
plugins = get_latest_versions(iter_plugins(client))
headers, rows = obtain_plugins_table(plugins, client)
generate_plugins_index_from_table(filename, headers, rows)
#===================================================================================================
# main
#===================================================================================================
def main(argv):
filename = os.path.join(os.path.dirname(__file__), 'plugins_index.txt')
"""
Script entry point. Configures an option parser and calls the appropriate
internal function.
"""
filename = os.path.join(os.path.dirname(__file__), 'index.txt')
url = 'http://pypi.python.org/pypi'
parser = OptionParser(description='Generates a restructured document of pytest plugins from PyPI')
parser.add_option('-f', '--filename', default=filename, help='output filename [default: %default]')
parser.add_option('-u', '--url', default=url, help='url of PyPI server to obtain data from [default: %default]')
parser = OptionParser(
description='Generates a restructured document of pytest plugins from PyPI')
parser.add_option('-f', '--filename', default=filename,
help='output filename [default: %default]')
parser.add_option('-u', '--url', default=url,
help='url of PyPI server to obtain data from [default: %default]')
(options, _) = parser.parse_args(argv[1:])
client = xmlrpclib.ServerProxy(options.url)
client = get_proxy(options.url)
generate_plugins_index(client, options.filename)
print
print '%s Updated.' % options.filename
print()
print('%s Updated.' % options.filename)
return 0
#===================================================================================================
# main
#===================================================================================================
# header for the plugins_index page
HEADER = '''.. _plugins_index:
List of Third-Party Plugins
===========================
The table below contains a listing of plugins found in PyPI and
their status when tested using py.test **{pytest_version}** and python 2.7 and
3.3.
A complete listing can also be found at
`pytest-plugs <http://pytest-plugs.herokuapp.com/>`_, which contains tests
status against other py.test releases.
'''
if __name__ == '__main__':
sys.exit(main(sys.argv))

View File

@@ -1,64 +0,0 @@
.. _plugins_index:
List of Third-Party Plugins
===========================
========================================================================================== ==================================================================================== ========= ====================================================================================================== ====================================================================================================== =============================================================================================================================================
Name Author Downloads Python 2.7 Python 3.3 Summary
========================================================================================== ==================================================================================== ========= ====================================================================================================== ====================================================================================================== =============================================================================================================================================
`pytest-bdd-0.6.7 <http://pypi.python.org/pypi/pytest-bdd/0.6.7>`_ `Oleg Pidsadnyi <oleg.podsadny@gmail.com>`_ 1640 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bdd-0.6.7?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bdd-0.6.7?py=py33&pytest=2.5.0 BDD for pytest
`pytest-bdd-splinter-0.5.96 <http://pypi.python.org/pypi/pytest-bdd-splinter/0.5.96>`_ `Oleg Pidsadnyi <oleg.podsadny@gmail.com>`_ 3463 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bdd-splinter-0.5.96?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bdd-splinter-0.5.96?py=py33&pytest=2.5.0 Splinter subplugin for Pytest BDD plugin
`pytest-bench-0.2.5 <http://pypi.python.org/pypi/pytest-bench/0.2.5>`_ `Concordus Applications <support@concordusapps.com>`_ 1588 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bench-0.2.5?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bench-0.2.5?py=py33&pytest=2.5.0 Benchmark utility that plugs into pytest.
`pytest-blockage-0.1 <http://pypi.python.org/pypi/pytest-blockage/0.1>`_ `UNKNOWN <UNKNOWN>`_ 110 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-blockage-0.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-blockage-0.1?py=py33&pytest=2.5.0 Disable network requests during a test run.
`pytest-browsermob-proxy-0.1 <http://pypi.python.org/pypi/pytest-browsermob-proxy/0.1>`_ `Dave Hunt <dhunt@mozilla.com>`_ 61 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-browsermob-proxy-0.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-browsermob-proxy-0.1?py=py33&pytest=2.5.0 BrowserMob proxy plugin for py.test.
`pytest-bugzilla-0.2 <http://pypi.python.org/pypi/pytest-bugzilla/0.2>`_ `Noufal Ibrahim <noufal@nibrahim.net.in>`_ 105 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bugzilla-0.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-bugzilla-0.2?py=py33&pytest=2.5.0 py.test bugzilla integration plugin
`pytest-cache-1.0 <http://pypi.python.org/pypi/pytest-cache/1.0>`_ `Holger Krekel <holger.krekel@gmail.com>`_ 5690 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cache-1.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cache-1.0?py=py33&pytest=2.5.0 pytest plugin with mechanisms for caching across test runs
`pytest-capturelog-0.7 <http://pypi.python.org/pypi/pytest-capturelog/0.7>`_ `Meme Dough <memedough@gmail.com>`_ 1615 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-capturelog-0.7?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-capturelog-0.7?py=py33&pytest=2.5.0 py.test plugin to capture log messages
`pytest-codecheckers-0.2 <http://pypi.python.org/pypi/pytest-codecheckers/0.2>`_ `Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>`_ 408 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-codecheckers-0.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-codecheckers-0.2?py=py33&pytest=2.5.0 pytest plugin to add source code sanity checks (pep8 and friends)
`pytest-contextfixture-0.1.1 <http://pypi.python.org/pypi/pytest-contextfixture/0.1.1>`_ `Andreas Pelme <andreas@pelme.se>`_ 101 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-contextfixture-0.1.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-contextfixture-0.1.1?py=py33&pytest=2.5.0 Define pytest fixtures as context managers.
`pytest-couchdbkit-0.5.1 <http://pypi.python.org/pypi/pytest-couchdbkit/0.5.1>`_ `RonnyPfannschmidt <ronny.pfannschmidt@gmx.de>`_ 215 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-couchdbkit-0.5.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-couchdbkit-0.5.1?py=py33&pytest=2.5.0 py.test extension for per-test couchdb databases using couchdbkit
`pytest-cov-1.6 <http://pypi.python.org/pypi/pytest-cov/1.6>`_ `Meme Dough <memedough@gmail.com>`_ 23787 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cov-1.6?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-cov-1.6?py=py33&pytest=2.5.0 py.test plugin for coverage reporting with support for both centralised and distributed testing, including subprocesses and multiprocessing
`pytest-dbfixtures-0.4.0 <http://pypi.python.org/pypi/pytest-dbfixtures/0.4.0>`_ `Clearcode - The A Room <thearoom@clearcode.cc>`_ 6332 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-dbfixtures-0.4.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-dbfixtures-0.4.0?py=py33&pytest=2.5.0 dbfixtures plugin for py.test.
`pytest-django-2.4 <http://pypi.python.org/pypi/pytest-django/2.4>`_ `Andreas Pelme <andreas@pelme.se>`_ 4935 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-2.4?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-2.4?py=py33&pytest=2.5.0 A Django plugin for py.test.
`pytest-django-lite-0.1.0 <http://pypi.python.org/pypi/pytest-django-lite/0.1.0>`_ `David Cramer <dcramer@gmail.com>`_ 1075 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-lite-0.1.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-django-lite-0.1.0?py=py33&pytest=2.5.0 The bare minimum to integrate py.test with Django.
`pytest-figleaf-1.0 <http://pypi.python.org/pypi/pytest-figleaf/1.0>`_ `holger krekel <py-dev@codespeak.net,holger@merlinux.eu>`_ 59 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-figleaf-1.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-figleaf-1.0?py=py33&pytest=2.5.0 py.test figleaf coverage plugin
`pytest-flakes-0.2 <http://pypi.python.org/pypi/pytest-flakes/0.2>`_ `Florian Schulze, Holger Krekel and Ronny Pfannschmidt <florian.schulze@gmx.net>`_ 1203 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-flakes-0.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-flakes-0.2?py=py33&pytest=2.5.0 pytest plugin to check source code with pyflakes
`pytest-greendots-0.2 <http://pypi.python.org/pypi/pytest-greendots/0.2>`_ `UNKNOWN <UNKNOWN>`_ 149 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-greendots-0.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-greendots-0.2?py=py33&pytest=2.5.0 Green progress dots
`pytest-growl-0.1 <http://pypi.python.org/pypi/pytest-growl/0.1>`_ `Anthony Long <antlong@gmail.com>`_ 65 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-growl-0.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-growl-0.1?py=py33&pytest=2.5.0 Growl notifications for pytest results.
`pytest-incremental-0.3.0 <http://pypi.python.org/pypi/pytest-incremental/0.3.0>`_ `Eduardo Naufel Schettino <schettino72@gmail.com>`_ 192 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-incremental-0.3.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-incremental-0.3.0?py=py33&pytest=2.5.0 an incremental test runner (pytest plugin)
`pytest-instafail-0.1.1 <http://pypi.python.org/pypi/pytest-instafail/0.1.1>`_ `Janne Vanhala <janne.vanhala@gmail.com>`_ 431 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-instafail-0.1.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-instafail-0.1.1?py=py33&pytest=2.5.0 py.test plugin to show failures instantly
`pytest-ipdb-0.1-prerelease <http://pypi.python.org/pypi/pytest-ipdb/0.1-prerelease>`_ `Matthew de Verteuil <onceuponajooks@gmail.com>`_ 99 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-ipdb-0.1-prerelease?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-ipdb-0.1-prerelease?py=py33&pytest=2.5.0 A py.test plug-in to enable drop to ipdb debugger on test failure.
`pytest-jira-0.01 <http://pypi.python.org/pypi/pytest-jira/0.01>`_ `James Laska <james.laska@gmail.com>`_ 94 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-jira-0.01?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-jira-0.01?py=py33&pytest=2.5.0 py.test JIRA integration plugin, using markers
`pytest-konira-0.2 <http://pypi.python.org/pypi/pytest-konira/0.2>`_ `Alfredo Deza <alfredodeza [at] gmail.com>`_ 99 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-konira-0.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-konira-0.2?py=py33&pytest=2.5.0 Run Konira DSL tests with py.test
`pytest-localserver-0.3.2 <http://pypi.python.org/pypi/pytest-localserver/0.3.2>`_ `Sebastian Rahlf <basti AT redtoad DOT de>`_ 470 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-localserver-0.3.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-localserver-0.3.2?py=py33&pytest=2.5.0 py.test plugin to test server connections locally.
`pytest-marker-bugzilla-0.06 <http://pypi.python.org/pypi/pytest-marker-bugzilla/0.06>`_ `Eric Sammons <elsammons@gmail.com>`_ 205 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marker-bugzilla-0.06?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marker-bugzilla-0.06?py=py33&pytest=2.5.0 py.test bugzilla integration plugin, using markers
`pytest-markfiltration-0.8 <http://pypi.python.org/pypi/pytest-markfiltration/0.8>`_ `adam goucher <adam@element34.ca>`_ 269 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-markfiltration-0.8?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-markfiltration-0.8?py=py33&pytest=2.5.0 UNKNOWN
`pytest-marks-0.4 <http://pypi.python.org/pypi/pytest-marks/0.4>`_ `adam goucher <adam@element34.ca>`_ 241 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marks-0.4?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-marks-0.4?py=py33&pytest=2.5.0 UNKNOWN
`pytest-monkeyplus-1.1.0 <http://pypi.python.org/pypi/pytest-monkeyplus/1.1.0>`_ `Virgil Dupras <hsoft@hardcoded.net>`_ 132 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-monkeyplus-1.1.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-monkeyplus-1.1.0?py=py33&pytest=2.5.0 pytest's monkeypatch subclass with extra functionalities
`pytest-mozwebqa-1.1.1 <http://pypi.python.org/pypi/pytest-mozwebqa/1.1.1>`_ `Dave Hunt <dhunt@mozilla.com>`_ 1087 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-mozwebqa-1.1.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-mozwebqa-1.1.1?py=py33&pytest=2.5.0 Mozilla WebQA plugin for py.test.
`pytest-oerp-0.2.0 <http://pypi.python.org/pypi/pytest-oerp/0.2.0>`_ `Leonardo Santagada <santagada@gmail.com>`_ 158 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-oerp-0.2.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-oerp-0.2.0?py=py33&pytest=2.5.0 pytest plugin to test OpenERP modules
`pytest-osxnotify-0.1.4 <http://pypi.python.org/pypi/pytest-osxnotify/0.1.4>`_ `Daniel Bader <mail@dbader.org>`_ 200 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-osxnotify-0.1.4?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-osxnotify-0.1.4?py=py33&pytest=2.5.0 OS X notifications for py.test results.
`pytest-paste-config-0.1 <http://pypi.python.org/pypi/pytest-paste-config/0.1>`_ `UNKNOWN <UNKNOWN>`_ 169 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-paste-config-0.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-paste-config-0.1?py=py33&pytest=2.5.0 Allow setting the path to a paste config file
`pytest-pep8-1.0.5 <http://pypi.python.org/pypi/pytest-pep8/1.0.5>`_ `Holger Krekel and Ronny Pfannschmidt <holger.krekel@gmail.com>`_ 5971 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pep8-1.0.5?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pep8-1.0.5?py=py33&pytest=2.5.0 pytest plugin to check PEP8 requirements
`pytest-poo-0.2 <http://pypi.python.org/pypi/pytest-poo/0.2>`_ `Andreas Pelme <andreas@pelme.se>`_ 116 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-poo-0.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-poo-0.2?py=py33&pytest=2.5.0 Visualize your crappy tests
`pytest-pydev-0.1 <http://pypi.python.org/pypi/pytest-pydev/0.1>`_ `Sebastian Rahlf <basti AT redtoad DOT de>`_ 107 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pydev-0.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-pydev-0.1?py=py33&pytest=2.5.0 py.test plugin to connect to a remote debug server with PyDev or PyCharm.
`pytest-qt-1.0.2 <http://pypi.python.org/pypi/pytest-qt/1.0.2>`_ `Bruno Oliveira <nicoddemus@gmail.com>`_ 140 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-qt-1.0.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-qt-1.0.2?py=py33&pytest=2.5.0 pytest plugin that adds fixtures for testing Qt (PyQt and PySide) applications.
`pytest-quickcheck-0.8 <http://pypi.python.org/pypi/pytest-quickcheck/0.8>`_ `Tetsuya Morimoto <tetsuya dot morimoto at gmail dot com>`_ 380 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-quickcheck-0.8?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-quickcheck-0.8?py=py33&pytest=2.5.0 pytest plugin to generate random data inspired by QuickCheck
`pytest-rage-0.1 <http://pypi.python.org/pypi/pytest-rage/0.1>`_ `Leonardo Santagada <santagada@gmail.com>`_ 64 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rage-0.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rage-0.1?py=py33&pytest=2.5.0 pytest plugin to implement PEP712
`pytest-random-0.02 <http://pypi.python.org/pypi/pytest-random/0.02>`_ `Leah Klearman <lklrmn@gmail.com>`_ 125 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-random-0.02?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-random-0.02?py=py33&pytest=2.5.0 py.test plugin to randomize tests
`pytest-rerunfailures-0.03 <http://pypi.python.org/pypi/pytest-rerunfailures/0.03>`_ `Leah Klearman <lklrmn@gmail.com>`_ 153 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rerunfailures-0.03?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-rerunfailures-0.03?py=py33&pytest=2.5.0 py.test plugin to re-run tests to eliminate flakey failures
`pytest-runfailed-0.3 <http://pypi.python.org/pypi/pytest-runfailed/0.3>`_ `Dimitri Merejkowsky <d.merej@gmail.com>`_ 96 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runfailed-0.3?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runfailed-0.3?py=py33&pytest=2.5.0 implement a --failed option for pytest
`pytest-runner-2.0 <http://pypi.python.org/pypi/pytest-runner/2.0>`_ `Jason R. Coombs <jaraco@jaraco.com>`_ 5726 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runner-2.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-runner-2.0?py=py33&pytest=2.5.0 UNKNOWN
`pytest-sugar-0.2.2 <http://pypi.python.org/pypi/pytest-sugar/0.2.2>`_ `Teemu, Janne Vanhala <orkkiolento@gmail.com, janne.vanhala@gmail.com>`_ 374 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-sugar-0.2.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-sugar-0.2.2?py=py33&pytest=2.5.0 py.test plugin that adds instafail, ETA and neat graphics
`pytest-timeout-0.3 <http://pypi.python.org/pypi/pytest-timeout/0.3>`_ `Floris Bruynooghe <flub@devork.be>`_ 4514 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-timeout-0.3?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-timeout-0.3?py=py33&pytest=2.5.0 pytest plugin to abort tests after a timeout
`pytest-twisted-1.4 <http://pypi.python.org/pypi/pytest-twisted/1.4>`_ `Ralf Schmitt <ralf@brainbot.com>`_ 257 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-twisted-1.4?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-twisted-1.4?py=py33&pytest=2.5.0 A twisted plugin for py.test.
`pytest-xdist-1.9 <http://pypi.python.org/pypi/pytest-xdist/1.9>`_ `holger krekel and contributors <pytest-dev@python.org,holger@merlinux.eu>`_ 8103 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xdist-1.9?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xdist-1.9?py=py33&pytest=2.5.0 py.test xdist plugin for distributed testing and loop-on-failing modes
`pytest-xprocess-0.8 <http://pypi.python.org/pypi/pytest-xprocess/0.8>`_ `Holger Krekel <holger@merlinux.eu>`_ 108 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xprocess-0.8?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-xprocess-0.8?py=py33&pytest=2.5.0 pytest plugin to manage external processes across test runs
`pytest-yamlwsgi-0.6 <http://pypi.python.org/pypi/pytest-yamlwsgi/0.6>`_ `Ali Afshar <aafshar@gmail.com>`_ 210 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-yamlwsgi-0.6?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-yamlwsgi-0.6?py=py33&pytest=2.5.0 Run tests against wsgi apps defined in yaml
`pytest-zap-0.1 <http://pypi.python.org/pypi/pytest-zap/0.1>`_ `Dave Hunt <dhunt@mozilla.com>`_ 69 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-zap-0.1?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-zap-0.1?py=py33&pytest=2.5.0 OWASP ZAP plugin for py.test.
========================================================================================== ==================================================================================== ========= ====================================================================================================== ====================================================================================================== =============================================================================================================================================
*(Downloads are given from last month only)*
*(Updated on 2013-12-12)*

View File

@@ -1,16 +0,0 @@
.. _plugins_index:
List of Third-Party Plugins
===========================
============================================ ============================= ========= ============================================================================================= ============================================================================================= ===================
Name Author Downloads Python 2.7 Python 3.3 Summary
============================================ ============================= ========= ============================================================================================= ============================================================================================= ===================
`pytest-plugin1-1.0 <http://plugin1/1.0>`_ `someone <someone@py.com>`_ 4 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-plugin1-1.0?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-plugin1-1.0?py=py33&pytest=2.5.0 some plugin
`pytest-plugin2-1.2 <http://plugin2/1.2>`_ `other <other@py.com>`_ 40 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-plugin2-1.2?py=py27&pytest=2.5.0 .. image:: http://pytest-plugs.herokuapp.com/status/pytest-plugin2-1.2?py=py33&pytest=2.5.0 some other plugin
============================================ ============================= ========= ============================================================================================= ============================================================================================= ===================
*(Downloads are given from last month only)*
*(Updated on 2013-10-20)*

View File

@@ -1,91 +0,0 @@
import os
import xmlrpclib
import pytest
#===================================================================================================
# test_plugins_index
#===================================================================================================
@pytest.mark.xfail(reason="issue405 fails, not py33 ready, not a core pytest test")
def test_plugins_index(tmpdir, monkeypatch):
'''
Blackbox testing for plugins_index script. Calls main() generating a file and compares produced
output to expected.
.. note:: if the test fails, a file named `test_plugins_index.obtained` will be generated in
the same directory as this test file. Ensure the contents are correct and overwrite
the global `expected_output` with the new contents.
'''
import plugins_index
# dummy interface to xmlrpclib.ServerProxy
class DummyProxy(object):
expected_url = 'http://dummy.pypi'
def __init__(self, url):
assert url == self.expected_url
def search(self, query):
assert query == {'name' : 'pytest-'}
return [
{'name': 'pytest-plugin1', 'version' : '0.8'},
{'name': 'pytest-plugin1', 'version' : '1.0'},
{'name': 'pytest-plugin2', 'version' : '1.2'},
]
def release_data(self, package_name, version):
results = {
('pytest-plugin1', '1.0') : {
'package_url' : 'http://plugin1',
'release_url' : 'http://plugin1/1.0',
'author' : 'someone',
'author_email' : 'someone@py.com',
'summary' : 'some plugin',
'downloads': {'last_day': 1, 'last_month': 4, 'last_week': 2},
},
('pytest-plugin2', '1.2') : {
'package_url' : 'http://plugin2',
'release_url' : 'http://plugin2/1.2',
'author' : 'other',
'author_email' : 'other@py.com',
'summary' : 'some other plugin',
'downloads': {'last_day': 10, 'last_month': 40, 'last_week': 20},
},
}
return results[(package_name, version)]
monkeypatch.setattr(xmlrpclib, 'ServerProxy', DummyProxy, 'foo')
monkeypatch.setattr(plugins_index, '_get_today_as_str', lambda: '2013-10-20')
output_file = str(tmpdir.join('output.txt'))
assert plugins_index.main(['', '-f', output_file, '-u', DummyProxy.expected_url]) == 0
with file(output_file, 'rU') as f:
obtained_output = f.read()
expected_output = get_expected_output()
if obtained_output != expected_output:
obtained_file = os.path.splitext(__file__)[0] + '.obtained.txt'
with file(obtained_file, 'w') as f:
f.write(obtained_output)
assert obtained_output == expected_output
def get_expected_output():
"""
:return: string with expected rst output from the plugins_index.py script.
"""
expected_filename = os.path.join(os.path.dirname(__file__), 'test_plugins_index.expected.txt')
expected_output = open(expected_filename, 'rU').read()
return expected_output.replace('pytest=2.X.Y', 'pytest={}'.format(pytest.__version__))
#===================================================================================================
# main
#===================================================================================================
if __name__ == '__main__':
pytest.main()

View File

@@ -20,9 +20,9 @@
Project examples
==========================
Here are some examples of projects using py.test (please send notes via :ref:`contact`):
Here are some examples of projects using ``pytest`` (please send notes via :ref:`contact`):
* `PyPy <http://pypy.org>`_, Python with a JIT compiler, running over
* `PyPy <http://pypy.org>`_, Python with a JIT compiler, running over
`21000 tests <http://buildbot.pypy.org/summary?branch=%3Ctrunk%3E>`_
* the `MoinMoin <http://moinmo.in>`_ Wiki Engine
* `sentry <https://getsentry.com/welcome/>`_, realtime app-maintenance and exception tracking
@@ -60,7 +60,7 @@ Here are some examples of projects using py.test (please send notes via :ref:`co
* `pytest-localserver <https://bitbucket.org/basti/pytest-localserver/>`_ a plugin for pytest that provides a httpserver and smtpserver
* `pytest-monkeyplus <http://pypi.python.org/pypi/pytest-monkeyplus/>`_ a plugin that extends monkeypatch
These projects help integrate py.test into other Python frameworks:
These projects help integrate ``pytest`` into other Python frameworks:
* `pytest-django <http://pypi.python.org/pypi/pytest-django/>`_ for Django
* `zope.pytest <http://packages.python.org/zope.pytest/>`_ for Zope and Grok
@@ -68,7 +68,7 @@ These projects help integrate py.test into other Python frameworks:
* There is `some work <https://github.com/Kotti/Kotti/blob/master/kotti/testing.py>`_ underway for Kotti, a CMS built in Pyramid/Pylons
Some organisations using py.test
Some organisations using pytest
-----------------------------------
* `Square Kilometre Array, Cape Town <http://ska.ac.za/>`_

View File

@@ -14,7 +14,7 @@ A *skip* means that you expect your test to pass unless the environment
And *xfail* means that your test can run but you expect it to fail
because there is an implementation problem.
py.test counts and lists *skip* and *xfail* tests separately. Detailed
``pytest`` counts and lists *skip* and *xfail* tests separately. Detailed
information about skipped/xfailed tests is not shown by default to avoid
cluttering the output. You can use the ``-r`` option to see details
corresponding to the "short" letters shown in the test progress::
@@ -29,13 +29,13 @@ corresponding to the "short" letters shown in the test progress::
Marking a test function to be skipped
-------------------------------------------
.. versionadded:: 2.0, 2.4
.. versionadded:: 2.0, 2.4
Here is an example of marking a test function to be skipped
when run on a Python3.3 interpreter::
import sys
@pytest.mark.skipif(sys.version_info >= (3,3),
@pytest.mark.skipif(sys.version_info < (3,3),
reason="requires python3.3")
def test_function():
...
@@ -51,7 +51,7 @@ You can share skipif markers between modules. Consider this test module::
# content of test_mymodule.py
import mymodule
minversion = pytest.mark.skipif(mymodule.__versioninfo__ >= (1,1),
minversion = pytest.mark.skipif(mymodule.__versioninfo__ < (1,1),
reason="at least mymodule-1.1 required")
@minversion
def test_function():
@@ -104,7 +104,7 @@ you can set the ``pytestmark`` attribute of a class::
"will not be setup or run under 'win32' platform"
As with the class-decorator, the ``pytestmark`` special name tells
py.test to apply it to each test function in the class.
``pytest`` to apply it to each test function in the class.
If you want to skip all test functions of a module, you must use
the ``pytestmark`` name on the global level::
@@ -149,6 +149,11 @@ on a particular platform::
def test_function():
...
If you want to be more specific as to why the test is failing, you can specify
a single exception, or a list of exceptions, in the ``raises`` argument. Then
the test will be reported as a regular failure if it fails with an
exception not mentioned in ``raises``.
You can furthermore prevent the running of an "xfail" test or
specify a reason such as a bug ID or similar. Here is
a simple test file with the several usages:
@@ -159,10 +164,10 @@ Running it with the report-on-xfail option gives this output::
example $ py.test -rx xfail_demo.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.5.1
collected 6 items
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 7 items
xfail_demo.py xxxxxx
xfail_demo.py xxxxxxx
========================= short test summary info ==========================
XFAIL xfail_demo.py::test_hello
XFAIL xfail_demo.py::test_hello2
@@ -175,8 +180,9 @@ Running it with the report-on-xfail option gives this output::
condition: pytest.__version__[0] != "17"
XFAIL xfail_demo.py::test_hello6
reason: reason
XFAIL xfail_demo.py::test_hello7
======================== 6 xfailed in 0.04 seconds =========================
======================== 7 xfailed in 0.05 seconds =========================
.. _`skip/xfail with parametrize`:
@@ -212,7 +218,7 @@ imperatively, in test or setup code::
if not valid_config():
pytest.xfail("failing configuration (but should work)")
# or
pytest.skipif("unsupported configuration")
pytest.skip("unsupported configuration")
Skipping on a missing import dependency
@@ -255,7 +261,7 @@ because markers can then be freely imported between test modules.
With strings you need to import not only the marker but all variables
everything used by the marker, which violates encapsulation.
The reason for specifying the condition as a string was that py.test can
The reason for specifying the condition as a string was that ``pytest`` can
report a summary of skip conditions based purely on the condition string.
With conditions as booleans you are required to specify a ``reason`` string.
@@ -286,4 +292,9 @@ The equivalent with "boolean conditions" is::
def test_function(...):
pass
.. note::
You cannot use ``pytest.config.getvalue()`` in code
imported before py.test's argument parsing takes place. For example,
``conftest.py`` files are imported before command line parsing and thus
``config.getvalue()`` will not execute correctly.

5
doc/en/status.txt Normal file
View File

@@ -0,0 +1,5 @@
pytest development status
================================
https://drone.io/bitbucket.org/hpk42/pytest

View File

@@ -2,31 +2,50 @@
Talks and Tutorials
==========================
.. sidebar:: Next Open Trainings
`professional testing with pytest and tox <http://www.python-academy.com/courses/specialtopics/python_course_testing.html>`_, 24-26th November 2014, Freiburg, Germany
.. _`funcargs`: funcargs.html
Tutorial examples and blog postings
Talks and blog postings
---------------------------------------------
.. _`tutorial1 repository`: http://bitbucket.org/hpk42/pytest-tutorial1/
.. _`pycon 2010 tutorial PDF`: http://bitbucket.org/hpk42/pytest-tutorial1/raw/tip/pytest-basic.pdf
Basic usage and fixtures:
- `Introduction to pytest, Andreas Pelme, EuroPython 2014
<https://www.youtube.com/watch?v=LdVJj65ikRY>`_.
- `pytest feature and release highlights (GERMAN, October 2013)
- `Advanced Uses of py.test Fixtures, Floris Bruynooghe, EuroPython
2014 <https://www.youtube.com/watch?v=IBC_dxr-4ps>`_.
- `Why i use py.test and maybe you should too, Andy Todd, Pycon AU 2013
<https://www.youtube.com/watch?v=P-AhpukDIik>`_
- `3-part blog series about pytest from @pydanny alias Daniel Greenfeld (January
2014) <http://pydanny.com/pytest-no-boilerplate-testing.html>`_
- `pytest: helps you write better Django apps, Andreas Pelme, DjangoCon
Europe 2014 <https://www.youtube.com/watch?v=aaArYVh6XSM>`_.
- :ref:`fixtures`
- `Testing Django Applications with pytest, Andreas Pelme, EuroPython
2013 <https://www.youtube.com/watch?v=aUf8Fkb7TaY>`_.
- `Testes pythonics com py.test, Vinicius Belchior Assef Neto, Plone
Conf 2013, Brazil <https://www.youtube.com/watch?v=QUKoq2K7bis>`_.
- `Introduction to py.test fixtures, FOSDEM 2013, Floris Bruynooghe
<https://www.youtube.com/watch?v=bJhRW4eZMco>`_.
- `pytest feature and release highlights, Holger Krekel (GERMAN, October 2013)
<http://pyvideo.org/video/2429/pytest-feature-and-new-release-highlights>`_
- `pytest introduction from Brian Okken (January 2013)
<http://pythontesting.net/framework/pytest-introduction/>`_
- `pycon australia 2012 pytest talk from Brianna Laugher
<http://2012.pycon-au.org/schedule/52/view_talk?day=sunday>`_ (`video <http://www.youtube.com/watch?v=DTNejE9EraI>`_, `slides <http://www.slideshare.net/pfctdayelise/funcargs-other-fun-with-pytest>`_, `code <https://gist.github.com/3386951>`_)
- `pycon 2012 US talk video from Holger Krekel <http://www.youtube.com/watch?v=9LVqBQcFmyw>`_
- `pycon 2010 tutorial PDF`_ and `tutorial1 repository`_
Fixtures and Function arguments:
- :ref:`fixtures`
- `monkey patching done right`_ (blog post, consult `monkeypatch
plugin`_ for up-to-date API)
@@ -39,8 +58,8 @@ Test parametrization:
Assertion introspection:
- `(07/2011) Behind the scenes of py.test's new assertion rewriting
<http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_
- `(07/2011) Behind the scenes of pytest's new assertion rewriting
<http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_
Distributed testing:
@@ -48,11 +67,11 @@ Distributed testing:
Plugin specific examples:
- `skipping slow tests by default in py.test`_ (blog entry)
- `skipping slow tests by default in pytest`_ (blog entry)
- `many examples in the docs for plugins`_
.. _`skipping slow tests by default in py.test`: http://bruynooghe.blogspot.com/2009/12/skipping-slow-test-by-default-in-pytest.html
.. _`skipping slow tests by default in pytest`: http://bruynooghe.blogspot.com/2009/12/skipping-slow-test-by-default-in-pytest.html
.. _`many examples in the docs for plugins`: plugin/index.html
.. _`monkeypatch plugin`: plugin/monkeypatch.html
.. _`application setup in test functions with funcargs`: funcargs.html#appsetup
@@ -66,17 +85,22 @@ Plugin specific examples:
Older conference talks and tutorials
----------------------------------------
- `pycon australia 2012 pytest talk from Brianna Laugher
<http://2012.pycon-au.org/schedule/52/view_talk?day=sunday>`_ (`video <http://www.youtube.com/watch?v=DTNejE9EraI>`_, `slides <http://www.slideshare.net/pfctdayelise/funcargs-other-fun-with-pytest>`_, `code <https://gist.github.com/3386951>`_)
- `pycon 2012 US talk video from Holger Krekel <http://www.youtube.com/watch?v=9LVqBQcFmyw>`_
- `pycon 2010 tutorial PDF`_ and `tutorial1 repository`_
- `ep2009-rapidtesting.pdf`_ tutorial slides (July 2009):
- testing terminology
- basic py.test usage, file system layout
- basic pytest usage, file system layout
- test function arguments (funcargs_) and test fixtures
- existing plugins
- distributed testing
- `ep2009-pytest.pdf`_ 60 minute py.test talk, highlighting unique features and a roadmap (July 2009)
- `ep2009-pytest.pdf`_ 60 minute pytest talk, highlighting unique features and a roadmap (July 2009)
- `pycon2009-pytest-introduction.zip`_ slides and files, extended version of py.test basic introduction, discusses more options, also introduces old-style xUnit setup, looponfailing and other features.
- `pycon2009-pytest-introduction.zip`_ slides and files, extended version of pytest basic introduction, discusses more options, also introduces old-style xUnit setup, looponfailing and other features.
- `pycon2009-pytest-advanced.pdf`_ contain a slightly older version of funcargs and distributed testing, compared to the EuroPython 2009 slides.

View File

@@ -13,7 +13,7 @@ writing conftest.py files
You may put conftest.py files containing project-specific
configuration in your project's root directory, it's usually
best to put it just into the same directory level as your
topmost ``__init__.py``. In fact, ``py.test`` performs
topmost ``__init__.py``. In fact, ``pytest`` performs
an "upwards" search starting from the directory that you specify
to be tested and will lookup configuration values right-to-left.
You may have options that reside e.g. in your home directory

View File

@@ -1,5 +1,5 @@
=======================================
py.test documentation index
pytest documentation index
=======================================
@@ -17,7 +17,7 @@ customize_: configuration, customization, extensions
changelog_: history of changes covering last releases
**Continuous Integration of py.test's own tests and plugins with Hudson**:
**Continuous Integration of pytest's own tests and plugins with Hudson**:
`http://hudson.testrun.org/view/pytest`_

View File

@@ -2,10 +2,10 @@
Mission
====================================
py.test strives to make testing a fun and no-boilerplate effort.
``pytest`` strives to make testing a fun and no-boilerplate effort.
The tool is distributed as part of the `py` package which contains supporting APIs that
are also usable independently. The project independent ``py.test`` command line tool helps you to:
The tool is distributed as a `pytest` package. Its project independent
``py.test`` command line tool helps you to:
* rapidly collect and run tests
* run unit- or doctests, functional or integration tests

View File

@@ -1,7 +1,7 @@
pytest_django plugin (EXTERNAL)
==========================================
pytest_django is a plugin for py.test that provides a set of useful tools for testing Django applications, checkout Ben Firshman's `pytest_django github page`_.
pytest_django is a plugin for ``pytest`` that provides a set of useful tools for testing Django applications, checkout Ben Firshman's `pytest_django github page`_.
.. _`pytest_django github page`: http://github.com/bfirsh/pytest_django/tree/master

View File

@@ -13,7 +13,7 @@ command line options
``--genscript=path``
create standalone py.test script at given target path.
create standalone ``pytest`` script at given target path.
Start improving this plugin in 30 seconds
=========================================
@@ -21,7 +21,7 @@ Start improving this plugin in 30 seconds
1. Download `pytest_genscript.py`_ plugin source code
2. put it somewhere as ``pytest_genscript.py`` into your import path
3. a subsequent ``py.test`` run will use your local version
3. a subsequent ``pytest`` run will use your local version
Checkout customize_, other plugins_ or `get in contact`_.

View File

@@ -19,7 +19,7 @@ command line options
``--traceconfig``
trace considerations of conftest.py files.
``--nomagic``
don't reinterpret asserts, no traceback cutting.
don't reinterpret asserts, no traceback cutting.
``--debug``
generate and show internal debugging information.
``--help-config``
@@ -31,7 +31,7 @@ Start improving this plugin in 30 seconds
1. Download `pytest_helpconfig.py`_ plugin source code
2. put it somewhere as ``pytest_helpconfig.py`` into your import path
3. a subsequent ``py.test`` run will use your local version
3. a subsequent ``pytest`` run will use your local version
Checkout customize_, other plugins_ or `get in contact`_.

View File

@@ -22,7 +22,7 @@
.. _`capturelog`: capturelog.html
.. _`junitxml`: junitxml.html
.. _`pytest_skipping.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_skipping.py
.. _`checkout the py.test development version`: ../../install.html#checkout
.. _`checkout the pytest development version`: ../../install.html#checkout
.. _`pytest_helpconfig.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_helpconfig.py
.. _`oejskit`: oejskit.html
.. _`doctest`: doctest.html

Some files were not shown because too many files have changed in this diff Show More