Compare commits

..

620 Commits
2.2.2 ... 2.4.2

Author SHA1 Message Date
holger krekel
4b395d56cc bump version of docs 2013-10-04 13:59:44 +02:00
holger krekel
018860d626 finalize release announcement, changelog 2013-10-04 12:34:47 +02:00
holger krekel
19a76337a4 add pluginmanager.do_configure(config) as a link to
config.do_configure() for plugin-compatibility
add some more plugins to plugin-test.sh
2013-10-04 11:36:45 +02:00
holger krekel
0780f2573f bump version to 2.4.2, regen docs 2013-10-03 19:09:18 +02:00
holger krekel
cec7d47c1f remove fd-fixing attempt at startup of pytest. It's
not clear it's actually needed and it's not nice
to still do FD-dupping when "-s" is specified.
2013-10-03 18:53:40 +02:00
holger krekel
3d00cd35fc fix python2.5 issues 2013-10-03 18:25:03 +02:00
holger krekel
5aa5b9748d fix argcomplete-test to use sys.argv[0] if it looks like a py.test executable 2013-10-03 18:02:54 +02:00
holger krekel
cb65c56037 fix issue365 and depend on a newer py versions which uses colorama
for coloring instead of its own ctypes hacks.
2013-10-03 17:46:36 +02:00
holger krekel
ae090740c5 always dupfile if os.dup is available 2013-10-03 16:47:55 +02:00
holger krekel
2248a31a44 more fixes regarding marking, in particular plugins should use add_marker/get_marker now. 2013-10-03 15:43:56 +02:00
holger krekel
9fdfa155fb fix issue354: avoid tmpdir fixture to create too long filenames especially
when parametrization is used
2013-10-03 14:22:54 +02:00
holger krekel
e49eca8d59 simplify the implementation of NodeKeywords getting rid of __ descriptors appearing there. 2013-10-03 13:53:22 +02:00
holger krekel
263b0e7d99 add setup.cfg for building sphinx_docs 2013-10-03 12:35:13 +02:00
Andreas Zeidler
42b1033385 allow test items to not be associated with a test function
this is needed for plugins like `pytest-pep8` or `pytest-flakes`
2013-10-02 15:55:28 +02:00
holger krekel
05f6422392 remove unused imports (using "importchecker" project) 2013-10-02 14:32:40 +02:00
holger krekel
f83a65c8ae Added tag 2.4.1 for changeset 8828c924acae 2013-10-02 12:41:03 +02:00
holger krekel
071960250f avoid "IOError: Bad Filedescriptor" on pytest shutdown by not closing
the internal dupped stdout (fix is slightly hand-wavy but work).
2013-10-02 12:39:01 +02:00
holger krekel
16d98541f2 reference CHANGELOG 2013-10-02 12:09:19 +02:00
holger krekel
2b8f4214c3 2.4.1 release preps 2013-10-02 09:16:51 +02:00
holger krekel
d3c9927fee fix regression reported by dstufft: regression when a 1-tuple ("arg",) is used
for specifying parametrization (the values of the parametrization were passed
nested in a tuple).
2013-10-02 08:08:26 +02:00
holger krekel
acc5679bc8 adapt changelog 2013-10-02 07:56:30 +02:00
holger krekel
2ba77cb1f4 merge 2013-10-02 07:49:11 +02:00
holger krekel
8f65418d34 Merged in dirn/pytest/dirn/adjust-syntax-for-parametrize-documentat-1380671670976 (pull request #72)
Adjust syntax for parametrize documentation
2013-10-02 07:48:41 +02:00
Andy Dirnberger
8ae79e09c0 Adjust syntax for parametrize documentation
Without the double colon, reStructuredText won't display treat the block that
follows as pre-formatted text. Also, with this change comes the need to change a
tab to spaces to align it with the adjacent lines.

--HG--
branch : dirn/adjust-syntax-for-parametrize-documentat-1380671670976
2013-10-01 23:54:34 +00:00
holger krekel
c62bfaefd6 add to CHANGELOG 2013-10-01 22:39:23 +02:00
Anthon van der Neut
236fff00ad complete_dotted: fix for #361, filecompleter on dot files had differing behaviour from bash
Now if the prefix to expands ends in the directory seperator, then
'..../.*' is globbed as well.
2013-10-01 16:33:15 +02:00
holger krekel
9b9355b8da fix typos (thanks @faassen) 2013-10-01 14:30:53 +02:00
holger krekel
446bcf44fb strike wrong yield_fixture paragraph 2013-10-01 14:25:59 +02:00
Floris Bruynooghe
1db6fc87c7 Allow unicode strings in parser.add_argument()
This fixes issue360 by also converting unicode strings to the argparse
syntax instead of just native strings.
2013-10-01 13:20:20 +01:00
holger krekel
895d52471b bump version to dev again, new CHANGELOG section for 2.4.1.dev. 2013-10-01 12:51:52 +02:00
holger krekel
d226b2faf4 release announcement, bump version numbers, some test adapatations because of random win32 test failures. 2013-10-01 12:37:11 +02:00
holger krekel
74ea94625a Added tag 2.4.0 for changeset af860de70cc3 2013-10-01 10:43:40 +02:00
holger krekel
f9927e457b bump version to 2.4.0 2013-10-01 10:43:36 +02:00
holger krekel
a71fdd26b3 fix usage docs for "-k" (addresses issue357) 2013-09-30 21:39:32 +02:00
holger krekel
2c7d00579b bump version, some windows test fixes, prevent logging from raising exceptions at the end (finally), add py25 to tox.ini. 2013-09-30 16:09:26 +02:00
holger krekel
de35b077a2 disallow yield in non-yield-fixtures for now. This is an incompataibility but we want to prepare for possibly merging fixture and yield_fixture some day. 2013-09-30 13:56:54 +02:00
holger krekel
086d4e4ced strike keyword argument in favour of new pytest.yield_fixture decorator 2013-09-30 13:42:39 +02:00
holger krekel
431ce79d94 add missing entry to CHANGELOG 2013-09-30 13:23:32 +02:00
holger krekel
db6f347db6 fix issue358 -- introduce new pytest_load_initial_conftests hook and make capturing initialization use it, relying on a new (somewhat internal) parser.parse_known_args() method.
This also addresses issue359 -- plugins like pytest-django could implement a pytest_load_initial_conftests hook like the capture plugin.
2013-09-30 13:14:16 +02:00
holger krekel
4b709037ab some more separation of core pluginmanager from pytest specific functionality.
Idea is to have the PluginManager be re-useable from other projects at some point.
2013-09-30 13:14:14 +02:00
holger krekel
d946299b0a shift pytest_configure/unconfigure/addoption/namespace hook calling to config object.
The _pytest.config module itself is no longer a plugin but the actual
config instance is plugin-registered as ``pytestconfig``.
This allows to put most pytest specific logic to _pytest.config instead
of in the core pluginmanager.
2013-09-30 13:14:14 +02:00
holger krekel
694c6fd0e7 localize some argcomplete-related functionality 2013-09-30 10:19:06 +02:00
holger krekel
8b1e53f6d3 avoid creation of file in os.getcwd() cc avanderneut 2013-09-30 08:36:31 +02:00
holger krekel
a930f44e60 introduce pluginmanager.ensure_teardown() which allows 2013-09-28 22:23:00 +02:00
holger krekel
ac19212b2d remove very likely unused pytest_plugin_unregister hook (pytest itself and all plugins i know don't use it) 2013-09-28 22:22:57 +02:00
holger krekel
03c314e3be refine fromdictargs to avoid an uncessary re-setup of the pluginmanager 2013-09-28 22:22:55 +02:00
holger krekel
fad7bd4393 simplify Config constructor 2013-09-28 22:22:53 +02:00
holger krekel
b80e875525 move FILE_OR_DIR constant out 2013-09-28 09:52:41 +02:00
holger krekel
1fc466e8ac add terminalreporter.section|line methods to print extra information. 2013-09-27 15:48:03 +02:00
holger krekel
209a0cd5b2 is actually a new feature, the syntax: pytest.mark.parametrize("arg1,arg2", ...) 2013-09-27 14:15:53 +02:00
holger krekel
9ddfd62848 re-order CHANGELOG and group it into "features" and "bugs" and "known incompatibilities" 2013-09-27 12:58:26 +02:00
holger krekel
48838727ae bump version 2013-09-27 12:43:49 +02:00
holger krekel
39503932a4 merge monkeypatch.replace into monkeypatch.setattr, also support monkeypatch.delattr. 2013-09-27 12:33:06 +02:00
holger krekel
da7133d201 fix some tests wrt to expecting output now that pytest does no
introduce unwanted "buffering" on "-s" calls.
2013-09-27 12:28:34 +02:00
holger krekel
684d7f8668 remove gittip mention for now. 2013-09-27 10:58:04 +02:00
holger krekel
1327eb7cef rework docs to demonstrate and discuss current yield syntax in more depth. 2013-09-27 10:21:23 +02:00
holger krekel
030c337c68 don't manipulate FDs at all if output capturing is turned off. 2013-09-27 09:49:39 +02:00
holger krekel
3ab9b48782 introduce yieldctx=True in the @pytest.fixture decorator. Refactor tests and docs. 2013-09-26 12:57:21 +02:00
holger krekel
2bdd034242 fix issue355: junitxml generates name="pytest" tag. 2013-09-26 08:45:50 +02:00
Anthon van der Neut
b5a83a6af1 argcomplete_win: skip testing of argcomplete on windows 2013-09-09 12:41:29 +02:00
holger krekel
d565df90ad fix issue333: fix a case of bad unittest/pytest hook interaction. 2013-09-09 09:56:53 +02:00
holger krekel
88dc5f8204 Merge pull request #6 from bubenkoff/fix-failing-travis
only force tox to upgrade
2013-09-08 23:12:07 -07:00
Anatoly Bubenkov
fb6282caaa only force tox to upgrade 2013-09-07 20:23:44 +02:00
holger krekel
f7f569f730 Merged in paylogic/pytest/parametrize-fails-when-values-are (pull request #68)
parametrize fails when values are unhashable - add test
2013-09-07 09:16:35 +02:00
Anatoly Bubenkov
63a924b922 parametrize fails when values are unhashable - tests
--HG--
branch : parametrize-fails-when-values-are
2013-09-07 02:30:09 +02:00
Anatoly Bubenkov
f5897498f3 initial
--HG--
branch : parametrize-fails-when-values-are
2013-09-06 22:42:54 +02:00
holger krekel
c478027805 make "import pdb ; pdb.set_trace()" work natively wrt capturing (no "-s" needed
anymore), turning ``pytest.set_trace()`` into a mere shortcut.
2013-09-06 15:29:00 +02:00
holger krekel
109e2f215f add nose.SkipTest for python2.6 -- which apparently is a subclass from python2.7 on.
addresses issue236
2013-09-06 12:48:54 +02:00
holger krekel
41df742faf fix <py27 tests with nose 2013-09-06 12:32:55 +02:00
holger krekel
86f70f5201 fix issue352: fix reference to py.path.local description in tmpdir documentation
(generally to be found at http://pytest.org/latest/tmpdir.html )
2013-09-06 12:16:05 +02:00
holger krekel
94ee37cdb3 - fix issue181: --pdb now also works on collect errors. This was
implemented by a slight internal refactoring and the introduction
  of a new hook ``pytest_exception_interact`` hook.

- fix issue341: introduce new experimental hook for IDEs/terminals to
  intercept debugging: ``pytest_exception_interact(node, call, report)``.
2013-09-06 11:56:04 +02:00
holger krekel
8360c1e687 xfail some tests for doctest support if pdbpp is installed 2013-09-06 10:07:06 +02:00
holger krekel
ca5d02df06 another way how bash reacts when no argcomplete is there? 2013-09-05 22:32:35 +02:00
holger krekel
c3fcf4d928 show more info if the test fails 2013-09-05 22:22:14 +02:00
holger krekel
517d498285 fix issue169: respect --tb=style with setup/teardown errors as well. 2013-09-05 15:43:19 +02:00
holger krekel
9686a4129c Merged in mcmtroffaes/pytest/fix-nose-docs (pull request #67)
Fix instructions for nose users.
2013-09-05 12:10:25 +02:00
Matthias C. M. Troffaes
b7d31952eb Fix instructions for nose users.
--HG--
branch : fix-nose-docs
2013-08-23 11:59:57 +01:00
holger krekel
b879074a64 refs issue290 -- move and refactor the test the string/int-id parametrization test (Which xfails) 2013-08-16 11:41:31 +02:00
holger krekel
4800aeaef7 Merged in markon/pytest (pull request #66)
Fix @parametrize.
2013-08-16 11:38:00 +02:00
holger krekel
ca7c1f5d8e merge pull request #27: correctly handle nose.SkipTest during collection. Thanks
Antonio Cuni, Ronny Pfannschmidt.  I did a few tweaks to the test and the
activation (depending on if unittest is imported at all).
2013-08-16 11:33:58 +02:00
Marco Buccini
f5a6a84314 test marked as 2013-08-16 09:55:25 +02:00
holger krekel
2888988eb6 fix manifest 2013-08-15 13:05:01 +02:00
holger krekel
e27dbdd071 Merged in bubenkoff/pytest/fix-broken-tests (pull request #65)
Fix broken python3 and python2.5 tests
2013-08-15 13:03:20 +02:00
Marco Buccini
6c54ee03de Fix @parametrize when using an integer and strings as parameters in a test accepting a parameter and a fixture as arguments. 2013-08-15 12:52:34 +02:00
Anatoly Bubenkov
0cd7effe35 fix broken python3 and python2.5 tests
--HG--
branch : fix-broken-tests
2013-08-15 11:52:55 +02:00
Anatoly Bubenkov
5851a99b82 initial
--HG--
branch : fix-broken-tests
2013-08-15 09:25:00 +02:00
holger krekel
863a206727 Merged in bubenkoff/pytest/overriden-fixture-finalizer (pull request #64)
overriden fixture finalizer tests
2013-08-15 07:06:25 +02:00
Anatoly Bubenkov
722b35b0a6 tests for fixture finalizers
--HG--
branch : overriden-fixture-finalizer
2013-08-14 13:58:59 +02:00
Anatoly Bubenkov
51dd63d3e1 ignores
--HG--
branch : overriden-fixture-finalizer
2013-08-14 10:09:02 +02:00
holger krekel
57f997b0b4 strike distribute dep 2013-08-11 18:19:58 +02:00
holger krekel
654212d93b add a note about how a lightweight but more powerful function-mocker could be done
(compared to standard mock).
2013-08-09 10:22:49 +02:00
holger krekel
88aa8f5435 mention pytest_collection_modifyitems in plugin page 2013-08-08 23:32:14 +02:00
holger krekel
0755d0605f remove automatic tox-testing of py25 2013-08-08 13:18:46 +02:00
holger krekel
4b88d6d2d7 monkeypatch.replace() now only accepts a string. Improved error handling and
docs thanks to suggestions from flub, pelme, schmir, ronny.
2013-08-07 16:49:29 +02:00
holger krekel
407283ef81 a new monkeypatch.replace(target, value) call which derives the
monkeypatch location from target (can be class/module/function or
string which is taken as importable python path)
examples:

    monkeypatch.replace(os.path.abspath, lambda x: "")
    monkeypatch.replace("requests.get", ...)
2013-08-07 15:35:27 +02:00
holger krekel
3fddf99661 Merged in anthon_van_der_neut/pytest_argcomplete (pull request #63)
argcomplete: FastFileCompleter that doesn't call bash in subprocess, strip prefix dir
2013-08-06 15:41:54 +02:00
holger krekel
21f72b7163 Merged in pelme/pytest/quiet-color-summary (pull request #61)
Added color to the quite mode summary
2013-08-06 15:38:43 +02:00
Anthon van der Neut
719e89fc1a argcomplete: FastFileCompleter that doesn't call bash in subprocess, strip prefix dir
```
timeit result for 10000 iterations of expanding '/d' (lowered the count in the code afterwards)
#                      2.7.5     3.3.2
# FilesCompleter       75.1109   69.2116
# FastFilesCompleter    0.7383    1.0760
```
- does not display prefix dir (like bash, not like compgen), py.test /usr/<TAB> does not show /usr/bin/ but bin/
2013-08-06 15:33:27 +02:00
Andreas Pelme
afa88a479b Added color to the quite mode summary. Also changed the output format
slightly to match the output of the standard summary.

--HG--
branch : quiet-color-summary
2013-08-05 09:45:10 +02:00
holger krekel
7d86827b5e ref #322 cleanup all teardown calling to only happen when setup succeeded.
don't use autouse fixtures for now because it would cause a proliferation
and overhead for the execution of every test.  Rather introduce a
node.addfinalizer(fin) to attach a finalizer to the respective node
and call it from node.setup() functions if the setup phase succeeded
(i.e. there is no setup function or it finished successfully)
2013-08-02 09:52:40 +02:00
holger krekel
b2ebb80878 fix issue322: tearDownClass is not run if setUpClass failed. Thanks
Mathieu Agopian for fixing.  The patch moves handling setUpClass
into a new autofixture. (XXX impl-decide if rather adding addfinalizer()
API to node's would have a similar effect)
2013-08-02 00:02:28 +02:00
Mathieu Agopian
7fc0d45a4c refs #322: setUpClass and tearDownClass as autouse fixture and finalizer 2013-08-01 23:48:40 +02:00
Ronny Pfannschmidt
3b85a56db2 merge 2013-08-01 22:55:16 +02:00
Ronny Pfannschmidt
743711cd1f fix issue317: assertion rewriter support for the is_package method 2013-08-01 22:11:18 +02:00
Floris Bruynooghe
cfe1d4f7c9 mention fix for issue 336 in changelog 2013-08-01 19:03:53 +01:00
Floris Bruynooghe
2cdb54225c Fix issue 336: autouse fixtures in plugins work again
When an autouse fixture in a plugin was encountered None was stored as nodeid
where it used to be ''.  This broke the lookup of autouse fixtures later on.

This also adds another test for the normal fixture ordering which was slightly
wrong: a fixture without location was always added at the front of the fixture
list rather then at the end of the fixtures without location but before the
fixtures with location.
2013-08-01 18:58:28 +01:00
holger krekel
8f24e10571 add changelog entry for anthon's hynek-fication of options,
and change the docs and tests to use the new style.
2013-08-01 17:32:19 +02:00
holger krekel
3ac36f6572 Merged in anthon_van_der_neut/pytest/opt-drop-non-hyphened-long-options (pull request #57)
changes to addoption() for hyphenated long-options
2013-08-01 17:04:18 +02:00
Anthon van der Neut
e96da76c3b changes to addoption() for hyphenated long-options
--HG--
branch : opt-drop-non-hyphened-long-options
2013-08-01 16:49:26 +02:00
holger krekel
ca6f3d24c3 Merged in anthon_van_der_neut/pytest/opt-drop-non-hyphened-long-options (pull request #56)
drop help for long options if longer versions with hyphens are available
2013-08-01 16:33:50 +02:00
Anthon van der Neut
e24b56af6c removed two superfluous parser arguments
--HG--
branch : opt-drop-non-hyphened-long-options
2013-08-01 16:27:06 +02:00
Anthon van der Neut
007a77c2ba drop help for long options if longer versions with hyphens are available
--HG--
branch : opt-drop-non-hyphened-long-options
2013-08-01 16:21:33 +02:00
Floris Bruynooghe
18fa7d866d Close issue 279: improved assertrepr_compare 2013-08-01 15:02:58 +01:00
holger krekel
9ccd52d538 fix issue305 - ignore any problems in writing a pyc file, but print out a trace. 2013-08-01 15:43:42 +02:00
holger krekel
cbbbfcd101 fix collection imports for python2.5 2013-08-01 15:38:03 +02:00
Mathieu Agopian
72a48d69cd refs #279: sequence assertions can also deal with (Mutable)Sequence instances 2013-08-01 14:48:34 +02:00
holger krekel
7e4b21e9a7 merge 2013-08-01 14:45:24 +02:00
holger krekel
b90d82c17f fix some py33 issues introduced with rev 2985
--HG--
branch : argcomplete
2013-08-01 14:24:25 +02:00
holger krekel
b60a8c12d5 fix Mathieu's name. 2013-08-01 12:12:09 +02:00
holger krekel
a24c7b42f1 add changelog entry for fixed issue 335. 2013-08-01 11:36:05 +02:00
Mathieu Agopian
0350a1929d merge 2013-08-01 11:20:30 +02:00
Mathieu Agopian
99783b6fba refs #335: clarify that the exception info returned by pytest.raises is a py.code.ExceptionInfo() 2013-08-01 11:19:47 +02:00
Mathieu Agopian
0e3abdc1af Merged hpk42/pytest into default 2013-08-01 11:12:59 +02:00
Mathieu Agopian
905c648b99 fixes #335: document ExceptionInfo returned by pytest.raises 2013-08-01 11:12:02 +02:00
holger krekel
b81c257360 small mod to test BND 2013-08-01 10:59:45 +02:00
holger krekel
64e9956770 plugin versions are displayed now. 2013-08-01 10:57:36 +02:00
holger krekel
2385553790 no funcargs for setup functions, rather use autouse fixtures. 2013-08-01 10:43:02 +02:00
holger krekel
4c6a11b8e1 remove an old issue. 2013-08-01 10:40:55 +02:00
holger krekel
1111d5b26b remove an entry 2013-08-01 10:37:45 +02:00
holger krekel
44d5524be2 Merged in anthon_van_der_neut/pytest/argcomplete (pull request #51)
fix for tests running subprocesses of py.test after test_argcomplete
2013-08-01 10:30:24 +02:00
holger krekel
1023390f53 fix issue334: don't recommend distribute but setuptools everywhere, also remove implicit distribute_setup support from setup.py. 2013-08-01 09:42:44 +02:00
holger krekel
02199c218d add license note to README 2013-08-01 09:31:34 +02:00
holger krekel
46901fb813 fix issue338: honor --tb style for setup/teardown errors as well. Thanks Maho.
(this is just changing the CHANGELOG entry because the bug was already fixed earlier)
2013-08-01 07:43:00 +02:00
Anthon van der Neut
ef2ddb6f16 monkeypatch for os.environment changes
--HG--
branch : argcomplete
2013-07-31 21:33:13 +02:00
Anthon van der Neut
e3a2e1bbf8 fix for tests running subprocesses of py.test after test_argcomplete
(which all still ran with argcompletion enabled) -> fail

--HG--
branch : argcomplete
2013-07-31 16:03:53 +02:00
holger krekel
8a0a880294 Merged in anthon_van_der_neut/pytest/argcomplete (pull request #50)
Fixes for argcomplete
2013-07-31 07:51:07 +02:00
Anthon van der Neut
6817a56270 minor adjustment, added test for positional argument completion
--HG--
branch : argcomplete
2013-07-30 12:33:38 +02:00
Anthon van der Neut
87860600fb Fixes for argcomplete
- separate out most argcomplete related stuff in new file _argcomplete.py
  (could probably be in the py library)
- allow positional arguments to be interspaced with optional arguments
  ( + test in test_parseopt.py )
- removed double argument in tox.ini
- add documentation on installing argcomplete (>=0.5.7 as needed for
  Python 3), might need improving/incorporation in index.

This does not work on 2.5 yet. I have patches for argcomplete
(with/print()/"".format) but I am not sure they will be accepted.
Agreed with hpk not to push for that.

Removing argcomplete and leaving completion code active now works by early
exit, so <TAB> no longer re-runs the programs without parameters
(which took long for py.test)

test calls bash with a script that redirects filedescriptor 8 (as used by
argcomplete), so the result can be tested.

--HG--
branch : argcomplete
2013-07-30 11:26:15 +02:00
holger krekel
377f63085a be more liberal with respect to lsof checks because jenkins keeps some files open 2013-07-29 15:39:24 +02:00
holger krekel
2a7c79dbf5 make genscript provide information as to compatibility
(now that argparse is a dependency on python2.6)
2013-07-26 08:59:31 +02:00
holger krekel
7a8134660f merge doc changes 2013-07-26 08:59:29 +02:00
holger krekel
863a255c9d Merged in anthon_van_der_neut/pytest/tox_reference (pull request #47)
update for links to tox
2013-07-26 08:59:12 +02:00
Anthon van der Neut
9b51105afa also update testrun.org in 日本語
--HG--
branch : tox_reference
2013-07-26 08:20:26 +02:00
Anthon van der Neut
4b56b075c1 updated tox to live on testrun.org (the old links are still
working on codespeak.net, but those docs are outdated)

--HG--
branch : tox_reference
2013-07-26 08:14:49 +02:00
holger krekel
788303523e add changelog: integrate option tab-completion when argcomplete is used. Thanks
Anthon van der Neut for the PR.  This also lets pytest use argparse
instead of optparse.
2013-07-26 07:51:33 +02:00
holger krekel
4b87810fc2 Merged in anthon_van_der_neut/pytest/argparse (pull request #46)
argparse / argcomplete
2013-07-26 07:41:43 +02:00
Anthon van der Neut
ad72e7f29d auto change %default -> %(default)s in help parameter string (on retrieval)
added code for warnings on optparse arguments (type, help),
which can be easily switched on with TYPE_WARN = True in config.py


installed and tested ( py.test --help )
pytest-quickcheck-0.7
pytest-gae-0.2.2
pytest-growl-0.1
pytest-bdd-0.4.7
pytest-bdd-splinter-0.4.4
pytest-cache-1.0
pytest-capturelog-0.7
pytest-codecheckers-0.2
pytest-contextfixture-0.1.1
pytest-cov-1.6
pytest-flakes-0.1
pytest-incremental-0.3.0
pytest-xdist-1.8
pytest-localserver-0.1.5
pytest-monkeyplus-1.1.0
pytest-oerp-0.2.0
pytest-pep8-1.0.4
pytest-pydev-0.1
pytest-rage-0.1
pytest-runfailed-0.3
pytest-timeout-0.3
pytest-xprocess-0.7
pytest-browsermob-proxy-0.1
pytest-mozwebqa-1.1.1
pytest-random-0.02
pytest-rerunfailures-0.03
pytest-zap-0.1
pytest-blockage-0.1
pytest-django-2.3.0
pytest-figleaf-1.0
pytest-greendots-0.1
pytest-instafail-0.1.0
pytest-konira-0.2
pytest-marker-bugzilla-0.06
pytest-marks-0.4
pytest-poo-0.2
pytest-twisted-1.4
pytest-yamlwsgi-0.6

--HG--
branch : argparse
2013-07-25 17:26:48 +02:00
Anthon van der Neut
15ec5a898c moving from optparse to argparse. Major difficulty is
that argparse does not have Option objects -> added class Argument
Needed explicit call of MyOptionParser.format_epilog as argparse
does not have that. The parse_arg epilog argument wraps the text,
which is not the same (could be handled with a special formatter).

- parser.parse() now returns single argument (with positional args in
  .file_or_dir)
- "file_or_dir" made a class variable Config._file_or_dir and used in help and tests
- added code for argcomplete (because of which this all started!)

addoption:
- if option type is a string ('int' or 'string', this converted to
  int resp. str
- if option type is 'count' this is changed to the type of choices[0]

testing:
- added tests for Argument
- test_mark.test_keyword_extra split as ['-k', '-mykeyword'] generates argparse
  error test split in two and one marked as fail
- testing hints, multiline and more strickt (for if someone moves format_epilog
  to epilog argument of parse_args without Formatter)
- test for destination derived from long option with internal dash
- renamed second test_parseopt.test_parse() to test_parse2 as it was
  not tested at all (the first was tested.)

--HG--
branch : argparse
2013-07-25 15:33:43 +02:00
holger krekel
9d9dd381bc mention github and bitbucket 2013-07-24 12:14:53 +02:00
holger krekel
997df928b7 stick to virtualenv<1.10 for now because it breaks python2.5 2013-07-24 12:08:20 +02:00
holger krekel
6d145ac93a bump version 2013-07-24 11:16:19 +02:00
holger krekel
1280add047 SO-17664702: call fixture finalizers even if the fixture function
partially failed (finalizers would not always be called before)
2013-07-17 10:29:11 +02:00
holger krekel
c53556b88d paint last line red if "failures" or "errors" occured, attribute theuni 2013-07-17 09:31:55 +02:00
holger krekel
60a53c75a6 some python2.5/3.3 fixes of Brianna's parametrize improvements 2013-07-16 15:43:20 +02:00
holger krekel
ca8281f229 merge better parametrize error messages, thanks Brianna Laugher 2013-07-16 15:32:05 +02:00
holger krekel
af7db5195b Merged in pfctdayelise/pytest (pull request #38)
A couple of improvements to parametrize
2013-07-16 15:30:48 +02:00
holger krekel
c2138e9733 add python testing training 2013-07-16 11:30:21 +02:00
holger krekel
31c1c69901 fix link to kotti 2013-07-11 16:07:58 +02:00
holger krekel
b7054495a7 send IRC notifications to pytest-dev 2013-07-11 12:20:38 +02:00
holger krekel
fc03c35bbd Merge pull request #3 from bubenkoff/travis-status-icon
correct travis build status image url
2013-07-11 03:08:27 -07:00
Anatoly Bubenkov
8320232f38 correct travis build status image url 2013-07-11 12:06:13 +02:00
holger krekel
52838a7834 Merge pull request #2 from bubenkoff/py25-test_skipping_faild
fixes for py25 in test_skipping
2013-07-11 02:30:01 -07:00
Anatoly Bubenkov
87eae6213e fixes for py25 in test_skipping 2013-07-11 11:15:31 +02:00
holger krekel
5d8b950b7f change copyright years 2013-07-11 10:50:59 +02:00
Anatoly Bubenkov
7b54476d71 Update README.rst
change the travis link and image to be correct
2013-07-10 13:51:43 +02:00
holger krekel
13ddce2381 fix issue320 - fix class scope for fixtures when mixed with
module-level functions.  Thanks Anatloy Bubenkoff.
2013-07-08 15:54:38 +02:00
holger krekel
be30eb22a6 fix docs wrt norecursedirs, thanks @mgax 2013-07-08 15:39:14 +02:00
Anatoly Bubenkov
589138ea71 re #320 fallback to test scope if the class-scoped fixture is used in non-class-based test function
--HG--
branch : 320-class-scoped-fixture-caching-is-broken-if
2013-07-06 21:30:24 +02:00
holger krekel
f7a9beaefb Merged in bubenkoff/pytest/329-skipif-requires-expression-as-a-string (pull request #43)
re #329 add test for skipif failure when you pass boolean without the reason. add emphasize to the docs.
2013-07-06 20:13:27 +02:00
Anatoly Bubenkov
214793f697 re #329 add test for skipif failure when you pass boolean without the reason. add emphasize to the docs.
--HG--
branch : 329-skipif-requires-expression-as-a-string
2013-07-06 18:54:24 +02:00
Floris Bruynooghe
c36186ce65 Always check for both ENOENT and ENOTDIR
This fixes issue 326.
2013-07-06 18:53:26 +02:00
Floris Bruynooghe
e6a063ee47 Solve fixture ordering when loading plugins from conftest
Conftests are plugins with a location attached to them while other
plugins do not have a location.  When ordering fixturedefs those from
plugins without a location need to be listed first.
2013-07-06 17:56:54 +02:00
holger krekel
723e414814 add KAsia to authors 2013-07-06 17:17:03 +02:00
holger krekel
a00b516f9a add kasia to changelog 2013-07-06 17:06:51 +02:00
holger krekel
31421cb6d7 merge 2013-07-06 16:03:48 +02:00
holger krekel
a6f2af23fb Merged in katarzynaanna/pytest (pull request #42)
Improved reporting
2013-07-06 16:03:27 +02:00
Katarzyna Jachim
ffa1bf726d merge 2013-07-06 15:54:33 +02:00
holger krekel
199f0314b9 Merged in bubenkoff/pytest/travis-integration (pull request #41)
add travis integration, fixes for py25 and py27 no pyc tox env
2013-07-06 15:51:14 +02:00
Katarzyna Jachim
87df85f12d improved reporting
added intermediate level of quiet reporting:
 * -q now shows short summary (# passed/failed tests + time)
 * the former -q is now -qq
2013-07-06 15:43:59 +02:00
holger krekel
ae327ef435 move to development doc target 2013-07-06 15:38:40 +02:00
Anatoly Bubenkov
1736242bd7 add travis integration, fixes for py25 and py27 no pyc tox env
--HG--
branch : travis-integration
2013-07-06 14:23:02 +02:00
Floris Bruynooghe
1a319056fc Mention issue 300 in changelog 2013-07-06 11:00:29 +02:00
Anatoly Bubenkov
ea7a997afc remove unnecessary print 2013-07-06 10:26:14 +02:00
Anatoly Bubenkov
2c7613c15c merge with upstream 2013-07-06 10:06:12 +02:00
Christian Theune
ab637e028b Merged in ctheune/pytest-greenbar-1/ctheune/typo-1372873724648 (pull request #1)
Typo
2013-07-03 19:49:28 +02:00
Christian Theune
1934f515ef Typo
--HG--
branch : ctheune/typo-1372873724648
2013-07-03 17:48:57 +00:00
Christian Theune
d9f0a28da2 Compatibility with my spinal cord reflexes: colorize last summary line.
Provide a red bar if there are any 'failures'. Otherwise make it green.
2013-07-03 19:43:18 +02:00
Christian Theune
ca88c02507 Support working in a local virtualenv. 2013-07-03 19:41:05 +02:00
holger krekel
ea4a3adfd6 - add my ep2013 talk to talks page
- add "talks/blogs" to the navigation side bar
2013-07-03 11:47:18 +02:00
holger krekel
c4c966683c fix issue323 - parametrize() of many module-scoped params 2013-06-28 12:57:10 +02:00
holger krekel
469830fffa some internal renaming to make more sense of the sorting algo,
no semantical changes.
2013-06-28 12:54:10 +02:00
holger krekel
f9720a38fe mention added support for setUpModule/tearDownModule detection, thanks Brian Okken. 2013-06-23 09:24:48 +02:00
Brian Okken
28b2859718 change how the test is called 2013-06-22 09:42:31 -07:00
Brian Okken
5e77eb23eb add test_unittest_style_setup_teardown()
to test setUpModule() and tearDownModule()
2013-06-22 09:35:10 -07:00
variedthoughts
3bcd3317ad support unittest setUpModule/tearDownModule 2013-06-20 14:43:42 +00:00
holger krekel
4af052b098 added some endorsements, not quite properly layouted 2013-06-20 14:05:16 +02:00
holger krekel
ac3d8800fd make sessionfinish hooks execute with the same cwd-context as at
session start (helps fix plugin behaviour which write output files
with relative path such as pytest-cov)
2013-06-10 10:09:28 +02:00
holger krekel
2951c3ace9 Merged in embray/pytest (pull request #37)
Adds a test for and fixes #112
2013-06-09 15:07:44 +02:00
Erik Bray
17e1106584 reindent a few of the blockquotes in these tests 2013-06-07 17:30:10 -04:00
holger krekel
7e2d4daa68 Merge pull request #1 from alfredodeza/297
add ref targets on recwarn
2013-06-03 07:13:04 -07:00
Alfredo Deza
0cfc4a49ea adding ref targets on recwarn 2013-06-03 10:07:14 -04:00
holger krekel
da1996b5f5 fix issue316 - properly reference collection hooks in docs 2013-06-03 10:04:50 +02:00
Brianna Laugher
345b8391c4 A couple of improvements to parametrize
- When not specifying ids, let None and bools use their native string form (like str, int, float) rather than obfuscated form used for objects
- When specifying ids, explicitly raise a ValueError if a different number of ids are specified compared to the test cases
- Add tests for both these items.
2013-05-29 12:59:47 +10:00
Erik Bray
b1595d3f61 Adds a test for and fixes #112. If attempting to write to the __pycache__ directory raises a permission error _write_pyc() should just return False to prevent any further write attempts. 2013-05-28 18:11:12 -04:00
holger krekel
c294a417bd allow to specify parametrize inputs as a comma-separated string
add Wouter to changelog and to authors
2013-05-28 10:32:54 +02:00
Benjamin Peterson
bc5a5a63f2 use __dict__ not func_dict for Python 3 compatibility 2013-05-27 14:04:53 -07:00
holger krekel
655afba17d Merged in w00t0r/pytest-fixes (pull request #35)
Fixed issue #306: Keywords and markers are now matched in a defined way. Also applied some pep8 formatting while fixing.
2013-05-27 21:40:41 +02:00
Wouter van Ackooy
212f4b4d64 Issue 306: Used a set for the extra_keywords, and used listchain for parent iteration. 2013-05-27 18:14:35 +02:00
Wouter van Ackooy
60906f7a46 Issue 306: Use the names of all the parents in the chain for matching, except the Instance objects. 2013-05-27 17:58:39 +02:00
Wouter van Ackooy
72afbbbd71 Added new test to check on matching markers to full test names, which was possible before. Also adjusted check on number of deselected tests. 2013-05-23 12:21:40 +02:00
Wouter van Ackooy
583c736f0c Added a test to check there is no matching on magic values. 2013-05-23 09:12:50 +02:00
holger krekel
8a0a18e9b3 - add Brianna (@pfctdayelise ) to changelog and contributors
- fix some broken tests on py32/py33 (related to issue308 merge)
- re-format docstrings
-
2013-05-22 15:24:58 +02:00
holger krekel
bbc61c85ac Merged in pfctdayelise/pytest (pull request #36)
issue 308
2013-05-22 13:36:39 +02:00
Wouter van Ackooy
02511d1564 Added lost space. 2013-05-22 07:41:46 +02:00
holger krekel
f78408df77 add holger's gittip account, would also like to add ronny's 2013-05-21 16:05:32 +02:00
Brianna Laugher
f2175146a9 Merged hpk42/pytest into default 2013-05-21 11:18:37 +10:00
Brianna Laugher
d8bc40271a issue #308
+ docs
2013-05-21 11:12:45 +10:00
Wouter van Ackooy
fe27f3cc7d Fixed issue #306: Keywords and markers are now matched in a defined way. Also applied some pep8 formatting while fixing. 2013-05-20 14:37:58 +02:00
Brianna Laugher
3aa0e4a526 ? pull/merge 2013-05-20 12:56:30 +10:00
Brianna Laugher
ee65ca10f4 issue #308
address some comments by @hpk42 on 0b9d82e :

- move tests into their own class, rename
- add test showing metafunc.parametrize called in pytest_generate_tests rather than as decorator
- add test and fix single-argname case
- convert two loops into one in parametrize()

also
- renamed 'input' to 'n', since 'input' is a built-in
2013-05-20 12:52:20 +10:00
holger krekel
afbeb056f0 added changelog for improved doctest counting 2013-05-17 20:48:51 +02:00
Danilo de Jesus da Silva Bellini
242b67de17 zero to many doctests from module instead of one 2013-05-17 12:18:22 -03:00
holger krekel
ed1095565b Merged hpk42/pytest into default 2013-05-17 11:32:52 +02:00
Brianna Laugher
5373a63008 issue #308
first attempt, mark individual parametrize test instances with other marks (like xfail)
2013-05-17 18:46:36 +10:00
holger krekel
e6e86fa462 fix issue307 - use yaml.safe_load instead of yaml.load, thanks Mark Eichin. 2013-05-16 09:59:48 +02:00
holger krekel
5a1ce3c45c add Jaap Broekhuizen for junitxml gen 2013-05-10 08:14:39 +02:00
holger krekel
67279418ff fix junitxml generation when test output contains control characters,
addressing issue267
2013-05-10 08:13:35 +02:00
holger krekel
1f1c24fe15 Merged in jaapz/pytest-xml-escape-control-chars (pull request #32)
Fix junitxml generation when using special characters in parametrized tests.
2013-05-10 08:06:31 +02:00
Jaap Broekhuizen
7803bca335 Implemented a test for xml control character fail. 2013-05-09 21:16:57 +02:00
holger krekel
c610c903f6 mention --tb style change in changelog 2013-05-09 15:50:28 +02:00
holger krekel
36e7cc1b9c honor --tb style for setup/teardown errors as well. 2013-05-09 15:50:09 +02:00
holger krekel
d69c9da656 add maho as contributor 2013-05-09 15:37:51 +02:00
holger krekel
a113c4c6d3 Merged in maho/pytest (pull request #31)
#299
2013-05-09 15:32:29 +02:00
maho
9e3cd03721 #299 - polishing 2013-05-08 17:01:20 +02:00
Jaap Broekhuizen
0e5f2847f1 Fix pytest.py permissions. 2013-05-08 16:11:55 +02:00
Jaap Broekhuizen
963b944e79 Fix junitxml generation when using special characters in parametrized tests. 2013-05-08 15:15:43 +02:00
holger krekel
55cd3d8bf3 bump version 2013-05-07 21:39:30 +02:00
holger krekel
150ad0172f document context fixtures, also improve plugin docs 2013-05-07 21:37:08 +02:00
holger krekel
9d8645b45d enhance index page, fix announcement index 2013-05-07 21:34:59 +02:00
holger krekel
bbd265184d support boolean condition expressions in skipif/xfail
change documentation to prefer it over string expressions
2013-05-07 18:40:26 +02:00
holger krekel
3279cfa28b don't use indexservers anymore 2013-05-07 16:26:56 +02:00
holger krekel
5fb4a100c9 Removed tag 1.4.14 2013-05-07 10:55:41 +02:00
holger krekel
71b4908233 Removed tag 1.4.14 2013-05-07 10:54:46 +02:00
holger krekel
77d2f6adde fix issue245 by depending on py-1.4.14 which fixes py.io.dupfile
to not assume file.mode is present.
2013-05-07 10:54:05 +02:00
holger krekel
51688270ac implemented as context managers. Thanks Andreas Pelme,
ladimir Keleshev.
fix issue245 by depending on the released py-1.4.14
which fixes py.io.dupfile to work with files with no
mode. Thanks Jason R. Coombs.
2013-05-07 10:53:31 +02:00
holger krekel
19f3e06ab0 Added tag 1.4.14 for changeset b93ac0cdae02 2013-05-07 10:48:13 +02:00
hg
d2dc797779 #299 2013-05-05 22:15:06 +02:00
holger krekel
56aa9962fc allow fixture functions to be implemented as context managers:
@pytest.fixture
def myfix():
    # setup
    yield 1
    # teardown
2013-05-05 14:48:37 +02:00
holger krekel
8e41ef5776 bump version 2013-05-05 14:48:17 +02:00
holger krekel
331bd84ef4 change version 2013-05-05 14:23:47 +02:00
holger krekel
4ac3445056 Added tag 2.3.5 for changeset fc3a793e87ec 2013-04-30 16:41:01 +02:00
holger krekel
8c7ae7f7a5 release 2.3.5 packaging 2013-04-30 12:26:30 +02:00
holger krekel
05c4ecf892 fix recursion within import hook and source.decode in particular 2013-04-30 12:05:58 +02:00
holger krekel
c5f9958783 never consider a fixture function for test function collection 2013-04-29 10:31:51 +02:00
Floris Bruynooghe
7a90515d49 Treat frozenset as a set
Thanks to Brianna Laugher.
2013-04-28 20:59:10 +01:00
Floris Bruynooghe
3ab94544b9 Ingore rope auto-generated files 2013-04-28 20:57:52 +01:00
Floris Bruynooghe
3c317dc35e Minor style cleanup 2013-04-28 20:56:56 +01:00
holger krekel
b2cb93e06d allow re-running of a test item (as exercised by the
pytest-rerunfailures plugins) by re-initializing and removing
request/funcargs information in runtestprotocol() - which is a slightly
odd place to add funcarg-related functionality but it allows all
pytest_runtest_setup/teardown hooks to properly see a valid
request/funcarg content on test items.
2013-04-22 10:35:48 +02:00
Floris Bruynooghe
c93fbb0e57 Load conftest files in the correct order initially
When the conftest.py files are looked for intially they got loaded
starting from the subdir ending at the parent dir(s).  Later on during
collection any conftest.py files are loaded starting from the parent
dir ending at the subdir.  Due to how extending fixtures works the
latter is correct as otherwise the wrong fixture will be available.
So this changes the initial conftest loading to start at the root and
go towards the subdir.

This does also affect the order of other hooks, hence the order of the
reporting being different in testing/test_terminal.py.
2013-04-18 12:24:53 +01:00
Ronny Pfannschmidt
cf7cae0780 pdb plugin: move entering pdb into a toplevel function
this prepares pdb at collect time
2013-04-18 11:18:24 +02:00
Ronny Pfannschmidt
55c349a9eb charify pdb visible stack end finding by turning it into a function 2013-04-16 10:19:20 +02:00
Ronny Pfannschmidt
73446e98be turn the postmortem traceback selection to a function 2013-04-16 10:18:08 +02:00
holger krekel
0bc98eb9d2 add to changelog: put captured stdout/stderr into junitxml output even
for passing tests (thanks Adam Goucher)
2013-04-16 09:14:47 +02:00
holger krekel
bfe9779b37 merge 2013-04-16 09:13:58 +02:00
holger krekel
bb6f3ebd31 slightly improve -k help string
cosmetic change to test_nose.py
2013-04-16 09:04:05 +02:00
holger krekel
ee69b43c7a Merged in adamgoucher/pytest (pull request #29)
stdout/stderr now captured by junitxml
2013-04-16 09:02:08 +02:00
Ronny Pfannschmidt
63a6936d82 move pdb plugin post morten traceback selection to a own function
this is preparation for making it resillent against broken envs
that can't import doctest
2013-04-16 08:46:55 +02:00
Adam Goucher
1cbd2db621 stdout/stderr now captured by junitxml 2013-04-16 00:45:14 -04:00
holger krekel
94aa76fec0 fix reference 2013-04-04 14:36:44 +02:00
Sasha Hart
265a4de06e doc fix: 'x' should be '-x' so it is not interpreted as a filename 2013-04-03 14:51:06 -05:00
holger krekel
712898cfe1 - add release announce 2013-03-28 10:21:03 +01:00
Floris Bruynooghe
f31dc7a8b7 Attempt to improve detailed failure reporting
* If --verbose is used do not truncate.

* Add a special dict comparison instead of diffing
  pprint output.
2013-03-28 01:39:01 +00:00
Ronny Pfannschmidt
9c9679945e fix Issue 265 - integrate nose setup/teardown with setupstate
as sideeffect teardown is only called if setup doesnt fail
2013-03-25 10:52:02 +01:00
Ronny Pfannschmidt
ba79c1926c add a test for issue 14 that will xfail on python < 2.7 2013-03-25 08:53:08 +01:00
Ronny Pfannschmidt
76fb51a4ba fix issue 271 - dont write junitxml on slave nodes 2013-03-24 20:43:25 +01:00
Ronny Pfannschmidt
93da606763 fix Issue 274 - dont fail when doctest does not know the example location
instead only the last test is shown, this could use some further enhancement
2013-03-24 20:05:29 +01:00
Benjamin Peterson
5e479c94ce disable assertion rewriting on CPython 2.6.0 because of bugs (fixes #280) 2013-03-21 12:19:01 -05:00
holger krekel
1884be0121 added changelog entry for getfixture() for doctests 2013-03-21 12:41:39 +01:00
holger krekel
8f8466ee40 Merged in witsch/pytest/doctest-fixtures (pull request #25)
fixture support in doctests
2013-03-21 12:33:43 +01:00
Andreas Zeidler
dfcb0e322c rename get_fixture to getfixture to better match the current API style
--HG--
branch : doctest-fixtures
2013-03-21 12:04:14 +01:00
Andreas Zeidler
da3b42ce46 remove debugging left-overs
--HG--
branch : doctest-fixtures
2013-03-21 01:03:59 +01:00
Andreas Zeidler
fa9bd8443f update the documentation regarding the get_fixture helper
please note that the japanese translation was done using "google translate" and should probably be checked again... :)

--HG--
branch : doctest-fixtures
2013-03-20 17:54:38 +01:00
Andreas Zeidler
5a3547dd7e also provide get_fixture helper for module level doctests
--HG--
branch : doctest-fixtures
2013-03-20 17:32:48 +01:00
Andreas Zeidler
c4b3a09886 test get_fixture helper for doctests
--HG--
branch : doctest-fixtures
2013-03-20 17:14:28 +01:00
Andreas Zeidler
f747d363b0 don't expose the FixtureRequest object itself in doctests. in most cases get_fixture is sufficient, and you can always call get_fixture('request') anyway
--HG--
branch : doctest-fixtures
2013-03-20 16:36:48 +01:00
Benjamin Peterson
65c69a34ac python 2.4 compatibility 2013-03-16 20:08:01 -07:00
Antonio Cuni
ba0100e057 (antocuni, ronny around): import directly from _pytest.runner to avoid the usage of @property 2013-03-14 16:53:57 +01:00
Antonio Cuni
37c47155e0 correctly handle nose.SkipTest during collection 2013-03-14 16:10:33 +01:00
Takafumi Arakaki
5ba2a7f628 Add texinfo build target to doc/*/Makefile 2013-03-10 07:25:14 +01:00
Benjamin Peterson
0cf79b29cd in the default Python 2 case, manually check the source is ASCII (fixes #269) 2013-03-08 10:44:41 -05:00
Floris Bruynooghe
6d1662e4b7 Use py.builtin._basestring 2013-02-15 13:38:40 +00:00
Floris Bruynooghe
850fd2b7f7 Mention fix of issue 266 in changelog 2013-02-15 13:28:26 +00:00
Floris Bruynooghe
48e6aa9dc7 Allow MarkEvaluator expressions to be unicode
This fixes issue #266.
2013-02-15 11:47:48 +00:00
Ronny Pfannschmidt
0dd05023b8 fix issue 251 - report a skip instead of ignoring classes with init 2013-02-15 10:18:00 +01:00
Ronny Pfannschmidt
aeba66ac6a fix typo in link 2013-02-14 14:15:13 +01:00
Ronny Pfannschmidt
d23f9fab46 update changelog 2013-02-14 13:17:05 +01:00
Ronny Pfannschmidt
69ef750091 fix issue134 - print the collect errors that prevent running specified test items 2013-02-14 12:21:42 +01:00
Ronny Pfannschmidt
ca8b3c2307 unify logic for error exit on test failures 2013-02-14 12:13:04 +01:00
holger krekel
857c99d354 fix py32 incompatible syntax 2013-02-14 12:17:23 +01:00
holger krekel
3785f1aae3 make dev pytest depend on installing from pypi.testrun.org 2013-02-14 11:57:32 +01:00
holger krekel
d0e18ac63f issue250 unicode/str mixes in parametrization names and values now works 2013-02-12 23:30:34 +01:00
holger krekel
296f752cca fix --genscript option to generate standalone scripts that also
work with python3.3 (importer ordering)
2013-02-12 22:59:29 +01:00
holger krekel
456731ed0f fix issue257 assertion-triggered compilation of source ending in a
comment line doesn't blow up in python2.5 (fixed through py>=1.4.13.dev6)
2013-02-12 22:43:33 +01:00
holger krekel
c8653b4c02 merge 2013-02-12 20:45:01 +01:00
holger krekel
e7a86caac2 strike python3.1 tox testing, 3.2 and 3.3 is enough 2013-02-12 20:44:04 +01:00
Ronny Pfannschmidt
162c3689c6 fix issue 260 - don't use nose specials on plain unittest cases 2013-02-07 17:53:13 +01:00
Ronny Pfannschmidt
b94c3084a6 small line length fix in nose plugin call optional 2013-02-07 10:41:07 +01:00
holger krekel
570ad36eaf fix parametrized testid to provide for uniqueness 2013-02-05 17:41:45 +01:00
holger krekel
9d107523a1 py3 fixes 2013-02-04 16:07:51 +01:00
holger krekel
06ab38a2fc strip old comment and hack 2013-02-03 20:47:39 +01:00
holger krekel
e007f2dc54 add note on leipzig course in june 2013 2013-02-02 20:15:01 +01:00
Andreas Zeidler
25547e3afb pass fixture request object (and convenience shortcut to get fixtures) into doctest files
--HG--
branch : doctest-fixtures
2013-01-30 17:32:37 +01:00
Ronny Pfannschmidt
64e6c71bf6 merge 2013-01-27 02:10:52 +01:00
Ronny Pfannschmidt
80f590288b add some bits to ISSUES 2013-01-27 02:10:29 +01:00
Ronny Pfannschmidt
570688f701 ensure OutcomeExceptions like skip/fail have initialized exception attributes 2013-01-27 02:06:19 +01:00
holger krekel
c5f587d6db don't test on py24 for now because tox/virtualenv-1.8 does not support
python2.4
2013-01-26 14:49:33 +01:00
holger krekel
ee713ad036 add Brian Okken's blog post as a tutorial 2013-01-21 09:04:01 +01:00
Floris Bruynooghe
51b40dd22c Add isolation plugin as a feature 2013-01-16 17:09:17 +00:00
Benjamin Peterson
65edf87ea6 display the repr of some global names (fixes #171) 2013-01-10 11:59:08 -06:00
holger krekel
4d4b551079 adapt locations of ML to new @python.org location 2012-12-27 16:48:17 +01:00
holger krekel
e13fedc256 fix pylib links 2012-12-27 16:48:14 +01:00
holger krekel
97f9bc2e46 fix/enhance example 2012-12-20 15:57:07 +01:00
holger krekel
d0bf65e6c8 adding an example on how to do interact with the list of collected tests once before any tests are run 2012-12-16 11:28:17 +01:00
holger krekel
8d25e52e1e add sentry 2012-12-15 08:09:23 +01:00
Dusty Phillips
6fefab0e3a pocoo no longer has a pastebin service, so this section title is incorrect. 2012-12-11 12:04:12 -07:00
holger krekel
1e94d900f2 fixed versioning, thanks Arfrever 2012-12-09 09:19:33 +01:00
holger krekel
5f99511ab7 fix test after ronny's pytest-debug improvements 2012-12-04 20:31:37 +01:00
holger krekel
22dd5e29e2 when informations gets truncated, mention use of "-vv" to see it. 2012-11-30 12:18:12 +01:00
Ronny Pfannschmidt
725e63db66 improve PYTEST_DEBUG tracing output
by putingextra data on a new lines
with additional indent
2012-11-29 10:04:39 +01:00
holger krekel
3d79e7060e allow to specify prefixes starting with "_" when
customizing python_functions test discovery. (thanks Graham Horler)
2012-11-28 09:23:36 +01:00
Graham Horler
1d7c71884e Remove check for "_" prefix on python functions (use python_functions)
(See IRC hpk 2012-11-27 14:56: after the python_functions customization
 was introduced, it makes sense to disregard the preliminary "_" check)
2012-11-27 16:58:08 +00:00
Wieland Hoffmann
ffb5b8efa1 Fix a broken link to pytest-twisted 2012-11-22 19:59:15 +01:00
holger krekel
68786a6434 fix bug where using capsys with pytest.set_trace() in a test
function would break when looking at capsys.readouterr()
2012-11-21 20:43:31 +01:00
holger krekel
b97de57ebe improve docstring for metafunc.parametrize() 2012-11-21 10:13:44 +01:00
holger krekel
03445913e0 reanme README.txt to README.rst 2012-11-20 14:37:39 +01:00
holger krekel
8580058ffb move long description into README 2012-11-20 14:24:26 +01:00
holger krekel
1c9ef2443f bump version, fix -k option help 2012-11-20 14:20:39 +01:00
holger krekel
cac1a48fc7 Added tag 2.3.4 for changeset ef299e57f242 2012-11-20 14:09:40 +01:00
holger krekel
b5955c5979 fix version number, final fixes 2012-11-20 14:01:31 +01:00
holger krekel
765b053984 bump version, add announcement, regen docs 2012-11-20 13:42:00 +01:00
holger krekel
a9adfa9114 don't run long-args test on windows because it can't work 2012-11-20 11:52:06 +01:00
holger krekel
7f403950ad adapt changelog entry about autouse fixtures and yield 2012-11-19 22:20:37 +01:00
holger krekel
f263f54889 make yielded tests participate in the autouse protocol 2012-11-19 22:17:59 +01:00
holger krekel
d66ff7e63e fix autouse invocation (off-by-one error), relates to issue in moinmoin test suite 2012-11-19 22:17:55 +01:00
holger krekel
f3e03fc298 modernize tmpdir fixture (use request.node in tmpdir fixture, use @pytest.fixture) 2012-11-19 14:07:14 +01:00
holger krekel
2ef350aede getting rid of redundant "active" attribute 2012-11-19 12:42:10 +01:00
holger krekel
b940ed11a0 fix issue226 - LIFO ordering for fixture-added teardowns 2012-11-16 10:03:51 +01:00
holger krekel
e15da7cbef add a note about yield tests at least in the CHANGELOG 2012-11-14 10:02:47 +01:00
holger krekel
5b64b0130d fix typo (thanks Thomas Waldmann) 2012-11-14 09:40:01 +01:00
holger krekel
af89a9667f add example for accessing test result information from fixture 2012-11-14 09:39:21 +01:00
holger krekel
c64c567b75 fix issue224 - invocations with >256 char arguments now work 2012-11-12 10:15:43 +01:00
ENDOH takanao
d31f4dcba8 Fix typos in a document 2012-11-10 16:29:43 +09:00
holger krekel
d9ce7f143e switch to pushing docs to dev, amend markers example which needs the dev candidate 2012-11-09 12:40:48 +01:00
holger krekel
4ac465acfb allow to pass expressions to "-k" option, just like with the "-m" option 2012-11-09 12:29:33 +01:00
holger krekel
a4909a0ae4 allow to dynamically define markers (e.g. during pytest_collection_modifyitems) 2012-11-09 12:07:41 +01:00
holger krekel
c790490387 add an example for postprocessing a test failure 2012-11-08 23:36:16 +01:00
holger krekel
664b01ca42 fix misleading typo 2012-11-08 19:05:46 +01:00
holger krekel
ff0c75aa34 - add a Package/dir level setup example
- make tox.ini's doc/regen use pytest release instead of dev version
2012-11-07 11:11:40 +01:00
holger krekel
476d210d09 prolong workaround for jython AST bug http://bugs.jython.org/issue1497
to make pytest work for post-2.5.1 jython versions
2012-11-07 10:05:39 +01:00
holger krekel
eedc4242ef mention that jython-2.5.1 works 2012-11-07 09:35:49 +01:00
holger krekel
370f5dd5cb fix typo 2012-11-06 15:46:52 +01:00
holger krekel
79f45928a4 add release announce for 2.3.3 2012-11-06 15:41:51 +01:00
holger krekel
dbff4ae034 Added tag 2.3.3 for changeset 7fe44182c434 2012-11-06 15:38:49 +01:00
holger krekel
d6f10d502c fix py31 compat, amend setup.py long description 2012-11-06 15:36:11 +01:00
holger krekel
65d6ebe7d1 bump to 2.3.3, add release announce 2012-11-06 14:41:10 +01:00
holger krekel
33cd414420 fix issue127 improve pytest_addoption docs, add new config.getoption(name) method for consistency. 2012-11-06 14:09:12 +01:00
holger krekel
dba2a8bc64 fix issue217 - to support @mock.patch with pytest funcarg-fixtures, also split out python integration tests into python/integration.py and fix nose/mark tests 2012-11-06 11:04:11 +01:00
holger krekel
f203401964 amend changelog entries 2012-11-06 09:27:58 +01:00
holger krekel
c64699bba6 fix issue219 - add trove classifiers for py24-py33 2012-11-06 09:14:41 +01:00
holger krekel
002c5072af addresses issue209 - avoid error messages from pip on python2.4 related to file, however, never be imported with this interpreter 2012-11-06 09:08:54 +01:00
Ronny Pfannschmidt
b3c8991b22 add a xfailing test for issue 199 2012-11-05 21:52:12 +01:00
Ronny Pfannschmidt
1a41c9c001 update changelog 2012-11-05 21:31:08 +01:00
Ronny Pfannschmidt
df444906d6 merge pull request 2012-11-05 21:18:50 +01:00
Ronny Pfannschmidt
04754f6748 test call_optional not calling non-callable functions 2012-11-05 21:17:58 +01:00
holger krekel
d5ad91c64f fix issue209 - depend on pylib dev version which again supports python2.4 2012-11-05 12:21:58 +01:00
holger krekel
7e831b66ec fix issue148 - recognize @unittest.skip on classes, avoid setup/teardown 2012-11-03 20:54:48 +01:00
holger krekel
ba9b27fcd3 fix issue215 - refactor test_python.py into multiple files:
- python/collect.py cotaining the core collection nodes
- python/fixture.py containing funcargs/fixture code
- python/metafunc.py generate_tests and metafunc usage
- python/raises.py the pytest.raises implementation
2012-11-02 16:04:57 +01:00
holger krekel
ca281b7c1b remove unused code 2012-11-02 16:04:56 +01:00
holger krekel
fb173a97a8 extended - fix issue214 - ignore attribute-access errors with objects in test modules that can blow up (for example flask's request object) 2012-10-31 17:00:55 +01:00
holger krekel
983b2d2475 merge 2012-10-31 17:01:24 +01:00
Ronny Pfannschmidt
e7e5ee805f fix issue 214 - gracefully handle proxy objects that look like fixtures 2012-10-31 17:00:43 +01:00
holger krekel
67f8dd0cf2 remove issue that doesn't make sense anymore 2012-10-28 17:40:30 +01:00
holger krekel
07cc48517d fix wrong reference in basic fixture example, thanks for reporting! (closes #212) 2012-10-28 14:54:49 +01:00
holger krekel
fce13c3e46 re-allow to parametrize with values that don't support __eq__ (closes issue213) 2012-10-28 14:52:43 +01:00
holger krekel
573599beb3 i think "helps you write better programs" fits better than "makes" 2012-10-28 11:25:53 +01:00
holger krekel
6ebf39e9a6 fix wrong document version on pytest.org (closes #210) 2012-10-28 10:13:37 +01:00
holger krekel
6b6080ae6c remove unused code 2012-10-28 10:12:36 +01:00
holger krekel
427cf6f66d add release announce 2012-10-25 14:13:43 +02:00
holger krekel
2fc8ee0839 Added tag 2.3.2 for changeset 8738b828dec5 2012-10-25 14:13:06 +02:00
holger krekel
6ad16936bb bump version to 2.3.2, regen docs and changelog 2012-10-25 13:48:31 +02:00
holger krekel
bcb8dc71d2 fix issue208 and fix issue29 - avoid long pauses in traceback printing
by using the new getstatementrange() code of the py lib which uses
AST-parsing rather than the previous heuristic which had O(n^2) complexity
(with n = len(sourcelines))

- require new (in-dev) py version to
2012-10-25 12:08:11 +02:00
holger krekel
b8277bfed8 fix issue127 - improve pytest_addoption and related documentation 2012-10-25 11:07:07 +02:00
holger krekel
2637326782 improve support for trial a bit more: don't run trial's empty TestCase.runTest() method 2012-10-22 19:22:01 +02:00
holger krekel
aa79c0a4b9 fix unittest emulation: TestCase.runTest is now ignored
if there are test* methods.
2012-10-22 16:25:09 +02:00
holger krekel
05c86aeb28 make sure ihook uses a node's fspath - important for hooks
e.g. during a Module's collect to pick up conftest.py files
residing in the same dir
2012-10-22 16:12:22 +02:00
holger krekel
f28f073c7c fix teardown-ordering for parametrized setups/teardowns 2012-10-22 12:16:54 +02:00
holger krekel
036557ac18 fix issue206 - unset PYTHONDONTWRITEBYTECODE in assertrewrite test 2012-10-22 11:14:18 +02:00
holger krekel
1b61fbc8ed - fix test_nose.py by being more tolerant about the error message
(differs between py32 and py33, thanks Arfrever)
- use pypi again now that py is released
2012-10-22 10:55:59 +02:00
holger krekel
97f03edcd6 fix issue205 - nested conftest to pickup pycollect_makemodule - relates to the two
reports of a failing doc/en/example/py2py3.
2012-10-22 10:17:50 +02:00
holger krekel
7e5efa0005 mention twisted with external plugins 2012-10-22 09:32:41 +02:00
holger krekel
d55fc611c4 properly handle non-existent PYTHONPATH 2012-10-20 17:39:15 +02:00
holger krekel
720fe3405b allow to run self-tests with "python setup.py test" for pytest tests itself 2012-10-20 17:32:03 +02:00
holger krekel
c894b2b459 add tox.ini to distribution 2012-10-20 17:08:02 +02:00
holger krekel
6d5bf4b908 Added tag 2.3.1 for changeset acf0e1477fb1 2012-10-20 14:33:23 +02:00
holger krekel
d4d213f83d some more fixes 2012-10-20 14:10:12 +02:00
holger krekel
289ee1c6ea prepare a 2.3.1 2012-10-20 14:05:33 +02:00
holger krekel
f41f7fda68 improve --markers output 2012-10-20 13:56:53 +02:00
holger krekel
9ed127b5da fix issue203 - fixture functions with a scope=function should have a "self" that points to the actual instance with which the test functions run. 2012-10-20 09:59:20 +02:00
holger krekel
525b08bc5c some doc refinements 2012-10-20 09:52:03 +02:00
holger krekel
fae34ca5e3 proper version number (2.3.1.dev*) 2012-10-19 16:00:29 +02:00
holger krekel
0852e84d9f skip pexpect using tests on freebsd 2012-10-19 15:59:29 +02:00
holger krekel
76db624639 start new dev cycle 2012-10-19 15:01:29 +02:00
holger krekel
1e6ec9941c Added tag 2.3.0 for changeset c27a60097767 2012-10-19 15:01:15 +02:00
holger krekel
a5ce481022 final touches 2012-10-19 11:12:13 +02:00
holger krekel
dca5fa2241 fixing links for 2.3 release, and fixing a windows32 failure on py3 2012-10-19 10:53:28 +02:00
holger krekel
586befb945 make usefixtures appear in py.test --markers output 2012-10-19 10:17:13 +02:00
holger krekel
b0b6695538 improve automatic id generation for parametrized tests 2012-10-19 10:07:13 +02:00
holger krekel
024df6e00b some more finalization of docs 2012-10-19 10:07:11 +02:00
holger krekel
5e28f461c8 avoid recursing into "ja" japanese examples 2012-10-18 15:32:30 +02:00
holger krekel
64544bee1a fix trial tests 2012-10-18 15:09:20 +02:00
holger krekel
7c8755cc89 refine docs, fix a marker/keywords bit, and add a test that request.keywords points to node.keywords. 2012-10-18 15:06:55 +02:00
holger krekel
7d747a1cde remove .markers attribute which was added in development and after 2.2.4
so never released.  Rather extend keywords to also exist on nodes. Assigning
to node.keywords will make the value appear on all subchildren's
keywords.
2012-10-18 13:52:32 +02:00
holger krekel
dbaedbacde many doc improvements and fixes 2012-10-18 12:24:50 +02:00
holger@merlinux.eu
cf17f1d628 fixing the fix of the last commit 2012-10-17 13:45:03 +02:00
holger krekel
67de2c53ac fix issue198 - detection of fixtures from conftest.py files in deeper nested dir structures with certain invocations 2012-10-17 13:42:40 +02:00
holger krekel
26ab80c4cd fix and test --fixtures location information 2012-10-17 13:12:33 +02:00
holger krekel
20849a44f5 improve --fixtures output with per-plugin grouping and hiding underscore names in non-verbose mode, re-introduce --funcargs for compatibiliy 2012-10-17 12:57:05 +02:00
holger krekel
51644a116c remove unused code 2012-10-17 11:50:32 +02:00
holger krekel
98513b995a simplify/integrate fixturemapper into FixtureManager
also fix jstests test failures
2012-10-17 11:20:45 +02:00
holger krekel
dc4e205876 typographic fixes, little simplification 2012-10-17 09:21:04 +02:00
holger krekel
2855a2f6cb remove outdated IMPL.txt and move up-to-date doc bits to FixtureMapper class. 2012-10-16 16:27:51 +02:00
holger krekel
cc2337af3a refine parsefactories interface, fix two_classes test originally reported by Alex Okrushko, also add a few more tests to make sure autouse-fixtures are properly distinguished 2012-10-16 16:13:12 +02:00
holger krekel
ab4183d400 strike another use of getfuncargnames() and rename FixtureDef.fixturenames to "argnames" because it's really just the fixture function arguments 2012-10-16 14:19:38 +02:00
holger krekel
37965657d0 make factorydeflist immutable by using an index 2012-10-16 13:59:12 +02:00
holger krekel
ccaa1af534 use FixtureInfo from FixtureRequest 2012-10-16 13:48:00 +02:00
holger krekel
2f3bbdafda use fixturemapper/fixtureinfo from Function objects 2012-10-16 13:48:00 +02:00
holger krekel
021c087701 implement fixture information stored on the parentnode of functions
to be reused by metafunc mechanics and Function setup
2012-10-16 13:47:59 +02:00
holger krekel
4541456a96 add plan for better fixture implementation, an xfailing test
and a slight refactoring of Metafunc tests/creation
2012-10-16 13:47:59 +02:00
holger krekel
f5d796b093 improve docs further, refine unittest docs, rename `autoactive to autouse`
to better match ``@pytest.mark.usefixtures`` naming.
2012-10-12 14:52:36 +02:00
ataumoefolau
40a55a640c nose.py: don't try to call setup if it's not callable 2012-10-12 14:39:17 +10:00
holger krekel
6eec2f5893 make tmpdir fixture always return a realpath()ed tmpdir and make a note
about it in the changed test.  Currently, i don't see a reason why this
is a bad idea (tm)
2012-10-11 13:05:16 +02:00
holger krekel
0594265adc fix output of --fixtures for @pytest.fixture defined functions. 2012-10-09 16:49:04 +02:00
holger krekel
fb3af07ef4 try to move docs to a more releasable state, also refine
release announce and a few coding bits
2012-10-09 14:35:17 +02:00
holger@merlinux.eu
39b8a19cf7 Fix test for windows 2012-10-08 13:42:31 +02:00
holger krekel
916c1c170e somewhat simplify pytest_generate_tests example 2012-10-08 13:19:31 +02:00
holger krekel
df643f65f0 remove support for @pytest.fixture on classes, to be reserved for future use:
Fixture-classes could offer setup/teardown/addoption/configure methods
and provide higher level support.  Preliminary allowing it to work on classes
may make introducing it harder.
2012-10-08 11:22:31 +02:00
holger krekel
d630d02c5b remove pytest.setup usage 2012-10-08 08:34:21 +02:00
holger krekel
30b10a6950 - fix doc references, refactor fixtures docs to more quickly start
with examples instead of big text blobgs
- also silence -q and -qq reporting some more
2012-10-07 13:06:17 +02:00
holger krekel
cda84fb566 - allow to use fixtures directly, i.e. without ()
- also allow scope to be determined by a dynamic function
2012-10-06 21:03:55 +02:00
holger krekel
d3893dd5d1 allow metafunc.parametrize(scope=...) calls to override the scope of a Fixture function definition. This is useful for cases where you want to dynamically
set scope and parametrization for a fixture instead of statically declaring
it on the fixture function.
2012-10-06 21:01:13 +02:00
holger krekel
55a8bfd174 fix issue197 - in case a function is parametrized with zero arguments,
skip it during setup
2012-10-06 11:34:06 +02:00
Floris Bruynooghe
f588eae4f5 Use updated names 2012-10-05 22:44:18 +01:00
holger krekel
d8c365ef2c implement pytest.mark.usefixtures and ini-file usefixtures setting
and also refine fixture docs a bit - fixtures.txt should now mostly
reflect the current state of the implementation
2012-10-05 19:20:40 +02:00
holger krekel
4cbb2ab3b3 bump version 2012-10-05 14:35:16 +02:00
holger krekel
d1a3f5c3a6 make the default non-error pass simpler and faster, refine error reporting by presenting "fixture" tracebacks 2012-10-05 14:24:45 +02:00
holger krekel
bb07ba7807 rename a number of internal and externally visible variables to use the fixture name
rather than funcargs.  Introduce .funcargnames compatibility attribute for backward compat.
2012-10-05 14:24:44 +02:00
holger krekel
8282efbb40 internally unify setup and fixture code, making setup a shortcut to fixture(autoactive=True) 2012-10-05 10:21:35 +02:00
holger krekel
9251e747af rename pytest.factory usages into pytest.fixture ones 2012-10-05 10:21:35 +02:00
holger krekel
439cc1238f merge factories/funcargs and setup functions into the new "fixture" document 2012-10-05 10:21:35 +02:00
holger krekel
3049af618c avoid pyc file issues by parametrizing the test instead of rewriting conftest.py files 2012-10-04 11:51:14 +02:00
holger krekel
7bc7a9b702 add py33 to tox.ini, report pypy-1.9 as working as well 2012-10-01 10:31:04 +02:00
holger krekel
5173647b4d fixes to against python3.3 2012-10-01 10:14:54 +02:00
holger krekel
57a832812b remove unneccessary internal __request__ funcarg. 2012-10-01 09:23:39 +02:00
Ronny Pfannschmidt
bee7543716 move Item.applymarker to Node, and defer to it from Funcargrequest.applymarker 2012-09-30 22:17:33 +02:00
holger krekel
b9767fd74c remove print, pass python32 2012-09-27 13:27:22 +02:00
holger krekel
dbe66f468a ensure proper calling of finalizers in case of parametrization on classes 2012-09-26 12:24:04 +02:00
Ronny Pfannschmidt
35cbb5791d fixes issue 156: monkeypatch class level descriptors 2012-09-25 18:15:13 +02:00
holger krekel
a18fd61a20 back out accidental changes introduced by last patch 2012-09-25 15:13:58 +02:00
holger krekel
a1c3d60747 add an xfail-ed test for a potential future "enabled" parameter to setup functions 2012-09-25 15:04:30 +02:00
holger krekel
fe4ccdff0e avoid double-instantiation of PluginManager in case of the "python pytest.py" or -m pytest invocation 2012-09-25 11:58:41 +02:00
holger krekel
cd1ead4f7b - make request.funcargnames carry the closure of all used funcargs
- make metafunc.funcargnames carry the closure of used funcargs
2012-09-24 17:04:34 +02:00
Ronny Pfannschmidt
9568ff3b23 backout, the _memoizedcall change worked only due to a local effect 2012-09-24 11:36:24 +02:00
Ronny Pfannschmidt
6e5f491a42 get rid of _memoizedcall - we dont really need it anymore 2012-09-24 11:26:38 +02:00
holger krekel
7768972ec5 make sure setups are called ahead of the funcarg factories of the test function 2012-09-24 10:36:22 +02:00
holger krekel
754fab9b55 merge 2012-09-22 20:26:13 +02:00
Ronny Pfannschmidt
253a87b2dc fix issue 191 - add support for runTest method of unittest.TestCase subclasses 2012-09-22 18:24:53 +02:00
holger krekel
81082ed3d3 extend --help to tell about --markers and --funcargs 2012-09-22 11:44:56 +02:00
holger krekel
465cfff6f9 don't call nose' setup methods if they are marked with pytest.setup 2012-09-22 00:23:36 +02:00
holger krekel
738f14a48a improve the parametrization scenario example to sort by id, rather than by file-order, see also: http://stackoverflow.com/questions/12521924/pytest-running-scenarios-in-the-correct-order-in-the-class 2012-09-21 09:39:54 +02:00
holger krekel
22dc47d9f9 refine internal test support for unicode-related bits (used by a test in pytest-pep8) 2012-09-20 10:57:23 +02:00
holger krekel
6cb3281ddd allow factory/setup-markers on classes, using their respective __init__ methods which can use the funcarg mechanism 2012-09-18 14:00:47 +02:00
holger krekel
a5e7e441d3 fix bug introduced with last checkin 2012-09-18 13:46:24 +02:00
holger krekel
a7c6688bd6 implement full @pytest.setup function unittest.TestCase interaction 2012-09-18 10:54:12 +02:00
holger krekel
d9c24552fc remove distinction of new versus old funcarg factories 2012-09-18 10:53:42 +02:00
holger krekel
631d311e89 - add request.node which maps to the collection node as specified by the scope.
- remove request.markers which is now available via request.node.markers
2012-09-17 20:43:37 +02:00
holger krekel
c2480f5c54 fix @funcarg to @factory 2012-09-17 17:36:08 +02:00
holger krekel
a94bb0a8bb introduce a new "markers" attribute to nodes and the request object. It is
a dynamic class making holdin
2012-09-17 17:32:23 +02:00
holger krekel
646c2c6001 drops special testcontext object in favour of "old" request object, simplifying communication and code for the 2.2-2.3 transition. also modify docs and examples. 2012-09-17 16:36:10 +02:00
holger krekel
f6b555f5ad merge 2012-09-17 08:41:04 +02:00
Ronny Pfannschmidt
bf5b226474 fix issue 188 - ensure sys.exc_info on py2 is clear before calling into a test 2012-09-15 15:20:49 +02:00
holger krekel
084c617b67 modify detection of factories located in plugins, allowing pytest's own test functions to access plugin defined funcargs even if they use internal machinery instead of a full test run 2012-09-12 12:51:45 +02:00
Ronny Pfannschmidt
bfaf8e50b6 fix issue 182: testdir.inprocess_run now considers passed plugins 2012-09-03 10:12:30 +02:00
Ronny Pfannschmidt
848c749d1a adapt the junit xml escaping test to my escaping changes 2012-09-03 09:54:02 +02:00
holger krekel
41ad7dbae1 fix issue185 monkeypatching time.time does not cause pytest to fail 2012-09-01 09:58:10 +02:00
holger krekel
93eac240a0 merge 2012-09-01 09:59:11 +02:00
Benjamin Peterson
a6060dfb6d use py3 compatible print syntax 2012-08-28 16:37:43 -04:00
Benjamin Peterson
7f36649763 remove usage of exception module, which is gone in py3.3 2012-08-28 16:35:06 -04:00
holger krekel
f07ebc6615 add talk from brianna and me from 2012 2012-08-26 16:30:01 +02:00
Ronny Pfannschmidt
e876ad9abd fix issue 179 - propperly show the dependency chain of factories on setup failure 2012-08-22 21:43:42 +02:00
Ronny Pfannschmidt
503addbf09 correctly have the test for issue #[C179 actually fail 2012-08-22 21:20:18 +02:00
Ronny Pfannschmidt
1318df4f5b add xfailing test for issue 179 2012-08-22 19:49:50 +02:00
Ronny Pfannschmidt
45693c2847 exchange the rawcode factory marker check with a more robust and specific instance check as advised by holger 2012-08-19 14:57:07 +02:00
Ronny Pfannschmidt
0e8cd9297a fix issue 176: raises(AssertionError) now catches builtin AssertionError as well 2012-08-19 13:45:26 +02:00
Ronny Pfannschmidt
0cca20bef9 ignore magic callables with no sane code in factory/setup discovery 2012-08-19 12:36:49 +02:00
Ronny Pfannschmidt
1446b4b4e6 fix issue #178 and extend the failure escape test 2012-08-17 16:08:08 +02:00
holger krekel
aa84359bd9 Merged in pfctdayelise/pytest (pull request #17) 2012-08-16 13:23:42 +02:00
Brianna Laugher
f275830ca7 expand list of projects based on URLs from holger 2012-08-16 19:31:21 +10:00
holger krekel
627e068516 fix issue172 so that @pytest.setup marked setup_module/function... functions
are not called twice.  Also fix ordering to that broader scoped setup
functions are executed first.
2012-08-13 13:37:14 +02:00
holger krekel
f472f21406 fix/update some docs to work with @pytest.factory instead of pytest_funcarg__ naming. 2012-08-13 12:58:08 +02:00
holger krekel
f4963270c6 fix typos 2012-08-11 20:02:34 +02:00
Brianna Laugher
08c3b1b80f Fix URL for waskr project 2012-08-10 15:44:58 +10:00
holger krekel
935761f098 also improve missing funcarg error for setup functions 2012-08-08 14:53:47 +02:00
holger krekel
dd268c1b2b improve error representation for missing factory definitions
in recursive funcarg reconstruction
2012-08-08 11:48:53 +02:00
holger krekel
172505f703 fix/consolidate --junitxml=path construction with relative pathes 2012-08-04 10:33:43 +02:00
holger krekel
6746a00cb8 majorly refine funcargs docs and rename "resources.txt" to "funcargs.txt" so that existing web links will eventually land at this new page when pytest is released. Also integrated the detailed reasoning and update setup function docs
to reflect latest discussions and feedback gathered on py-dev mailing list.
2012-08-03 19:08:27 +02:00
holger krekel
46dc7eeacb move pytest.mark.factory/setup to pytest.factory/setup, as per flub 's suggestion 2012-08-02 12:41:46 +02:00
holger krekel
ae241a5071 refine documentation, move setup to own "setup" page and provide
some more examples. move old setup_module/... to xunit_old page.
2012-08-02 12:07:54 +02:00
holger krekel
5fd84c35dd reshuffle docs, try to get a bit closer to release-relevant documentation 2012-08-01 14:52:51 +02:00
holger krekel
535d892f27 - rename @funcarg to @factory
- introduce a "testcontext" object for new-style funcargs and setup methods
- New-style funcargs and setup methods cannot use the "request" object anymore.
2012-08-01 13:57:09 +02:00
holger krekel
cb2eb9ba33 reorder internal layout so that funcarg-related functionality is in python.py 2012-08-01 09:23:39 +02:00
holger krekel
4f94ab4e42 mark a test as xfailing on python2.5 2012-08-01 09:10:40 +02:00
holger krekel
449b55cc70 - enhance ordering of tests using parametrized resources
- introduce a refined way to perform finalization for setup functions
  which does not use cached_setup() anymore
2012-08-01 09:07:32 +02:00
holger krekel
9dc79fd187 introduce a funcargcall object, holding meta information 2012-07-30 12:39:45 +02:00
holger krekel
b57fb9fd47 introduce a SetupCall, holding meta information and setup calling state 2012-07-30 11:51:50 +02:00
holger krekel
d68c65b493 minimize active parametrized non-function scoped resources by
- re-ordering at collection time
- modifying setup/teardown
2012-07-30 10:46:03 +02:00
holger krekel
fa61927c6b introduce @pytest.mark.setup decorated function,
extend newexamples.txt and draft a V4 resources API doc.
2012-07-24 12:10:04 +02:00
holger krekel
d4a487c725 allow funcarg factories to receive funcargs 2012-07-23 10:55:09 +02:00
holger krekel
76584b53a1 clarify and add to sort-by-session-scoped parametrized resources example 2012-07-23 10:54:57 +02:00
holger krekel
6b0f0adf5b implement a scope/parametrized examples using the so-far new features
also fix a bug with scoping/parametrization
2012-07-20 14:16:50 +02:00
holger krekel
396045e53f allow registration of "funcarg" marked factories 2012-07-20 14:16:49 +02:00
holger krekel
80db25822c implement funcarg factory scope marker and ScopeMismatch detection 2012-07-20 14:16:46 +02:00
holger krekel
f358fe7154 extend Metafunc and write a pytest_generate_tests hook on the funcarg manager
which discovers factories
2012-07-20 14:16:46 +02:00
holger krekel
e14459d45c discover funcarg factories independently from request/Function items 2012-07-20 14:16:28 +02:00
holger krekel
4e4b507472 move funcarg factory to a new FuncargManager object at session level 2012-07-19 09:20:14 +02:00
holger krekel
c7ee6e71ab re-introduce the old 2.2.4 FuncargRequest implementation as it is a better
base for implementing the new funcarg/setup api. Also Un-optimize
funcargnames discovery for now.
2012-07-18 19:49:14 +02:00
holger krekel
4766497515 V3 draft of resource api 2012-07-16 11:11:26 +02:00
holger krekel
38b18c44e9 ci 2012-07-18 19:48:43 +02:00
Wes Turner
a73c27da13 DOC: typo in doc/en/goodpractices.txt ("pytest" -> "PyTest") 2012-07-18 01:01:37 -05:00
holger krekel
dbaf7ee9d0 v2 of resources API draft 2012-07-16 10:47:41 +02:00
holger krekel
7a90bed19b V1 of the resources API draft 2012-07-16 10:47:00 +02:00
holger krekel
8adac2878f put automatic funcarg_ API to Py*objects only, refine internal subclassing and initialisation logic 2012-07-16 10:46:44 +02:00
holger krekel
66ed2d123a add a little example on how to group test execution by parametrized resource 2012-07-14 12:06:58 +02:00
Johannes
b902c36bfc Fix typo in terminal help text 2012-07-12 17:00:48 +01:00
Benjamin Peterson
099ac1e1f4 cleanup test a bit 2012-07-07 08:01:44 -07:00
Floris Bruynooghe
1aca6c9d7c Fix extension of of cached re-written file
With PYTHONOPTIMIZE set this had the extension of "o" instead of ".pyo".
Fixes issue #168.
2012-07-07 16:09:53 +02:00
Ronny Pfannschmidt
fe24e01a03 merge 2012-07-07 13:21:45 +02:00
holger krekel
838e758cf7 exit with errno instead of always signalling success, thanks John Anderson 2012-07-07 07:40:51 +02:00
holger krekel
ddd4467fdd merge 2012-07-02 13:23:41 +02:00
holger krekel
5574e45749 fix issue165 - fix broken links in documentation, also point to stackoverflow from FAQ and contact page 2012-07-02 13:13:48 +02:00
Ronny Pfannschmidt
74e55493d1 test and implement showing verbose assert repr for py.test -vv 2012-06-27 17:26:55 +02:00
holger krekel
ecec653e98 fix issue151 - heuristcally lookup conftest files on all command line arguments, not just the first existing dir/file
you can install the corresponding pytest-2.3.dev2 via
pip install -i http:/pypi.testrun.org -U pytest
2012-06-26 21:56:03 +02:00
holger krekel
0ba0f91720 remove unused code 2012-06-26 20:28:09 +02:00
holger krekel
ea49993459 fix issue139 - make it possible to access funcargs from pytest_runtest_setup 2012-06-25 18:08:12 +02:00
holger krekel
b4b86159cd better name for the oejskit-compatibility-class. 2012-06-25 17:49:13 +02:00
holger krekel
91b6f2bda8 mid-scale refactoring to make request API available directly on items.
This commit was slightly tricky because i want to backward
compatibility especially for the oejskit plugin which
uses Funcarg-filling for non-Function objects.
2012-06-25 17:35:33 +02:00
holger krekel
227d847216 fix problem with unicode in writing failure representations to terminal, thanks ThomasWaldmann 2012-06-24 16:42:31 +02:00
holger krekel
6e0c30d67d fix skip/xfail confusion, reported and discussed on
http://stackoverflow.com/questions/11105828/in-py-test-when-i-explicitly-skip-a-test-that-is-marked-as-xfail-how-can-i-get
2012-06-23 11:32:32 +02:00
holger krekel
65cbf591d8 ignore .cache 2012-06-22 10:53:28 +02:00
holger krekel
e79a312b92 fix internal test setup failure 2012-06-21 11:30:10 +02:00
holger krekel
42d44bfd43 fix some pep8 issues, more to go ... is there a tool that helps with pep8-ifying? 2012-06-21 11:20:29 +02:00
holger krekel
ccc04b9fc4 some refinements to reporting and hook order 2012-06-21 11:07:22 +02:00
holger krekel
18306a4644 add header info: always report 3rd party plugins in test runs 2012-06-20 00:16:47 +02:00
holger krekel
1bbe1d086c fix issue160 a failing setup of an xfail-marked tests should
be reported as xfail (not xpass)
2012-06-19 23:48:39 +02:00
holger krekel
672919a8e2 fix faq once more to get rid of the strange "missed" bit. 2012-06-18 11:47:57 +02:00
holger krekel
f176ee3a1c (correction-commit for wrong previous changelog message)
fix issue159 -- improve http://pytest.org/latest/faq.html
especially with respect to the "magic" history, also mention
pytest-django, trial and unittest integration.
2012-06-17 11:01:14 +02:00
holger krekel
474b177da8 fix issue129 - improve http://pytest.org/latest/faq.html
especially with respect to the "magic" history, also mention
pytest-django, trial and unittest integration.
2012-06-17 10:59:30 +02:00
holger krekel
b2e87ce027 change pluginmanager.register API to raise ValueError if the plugin object or the name is already registered 2012-06-16 21:29:04 +02:00
holger krekel
2e163e4aae mention pep302 in docstring 2012-06-16 10:14:52 +02:00
holger krekel
63eacd9dd5 fix comment handling 2012-06-12 13:41:29 +02:00
holger krekel
b008e489ba fix ReST errors, increment doc-version and push to pytest.org 2012-06-11 16:24:42 +02:00
Floris Bruynooghe
d5078001c9 Don't use deprecated API in example 2012-06-11 13:24:30 +01:00
holger krekel
8b3ac3b03a also set release 2012-06-07 19:26:18 +02:00
holger krekel
6af20a5290 use doc-versions that can increment separately from the pytest version 2012-06-07 19:18:50 +02:00
holger krekel
eb1b1005ae added an example on how to do python2/python3 customized test collection 2012-06-07 12:39:53 +02:00
holger krekel
6fd57ec786 extend marker section with a platform example 2012-06-06 16:34:13 +02:00
t2y
03a814a859 added Japanese translation for 2.2.4 (79a5b776a6f3) 2012-06-06 08:58:02 +09:00
t2y
b4c2161e35 fixed to find the CHANGELOG's path 2012-06-06 08:54:35 +09:00
t2y
9198069739 added "docs/en" directory and moved 2012-06-06 08:52:53 +09:00
holger krekel
4d77653bb0 simplify activate_funcargs 2012-06-03 21:06:43 +02:00
holger krekel
3f17784386 fix issue128 - show captured output when capsys/capfd are in use 2012-06-03 21:01:27 +02:00
holger krekel
971f96468c fix py2py3 example tests 2012-06-03 16:10:10 +02:00
holger krekel
c11202b549 remove pyc file 2012-06-01 20:13:18 +02:00
holger krekel
42d63832b7 draft example for skipping py2 and py3 only tests on
a per-module level.
2012-05-23 23:40:41 +02:00
holger krekel
f5f3fe54d5 update examples with 2.2.4 version, ReST fixes 2012-05-22 18:30:34 +02:00
holger krekel
76ec623b22 Added tag 2.2.4 for changeset ad9fe504a371 2012-05-22 18:27:49 +02:00
holger krekel
69fc6987ad upgrade inlined distribute_setup.py 2012-05-22 17:24:43 +02:00
holger krekel
0790f7a75f fix issue 144 - wrong classname in junitxml 2012-05-22 17:18:04 +02:00
Ronny Pfannschmidt
db8fbe7661 skip test for pyo on pypy since pypy doesnt do pyo 2012-05-22 16:20:58 +02:00
Jonathan Peirce
91c41cd6b3 minor fix to docs/usage 2012-05-22 12:24:53 +01:00
holger krekel
1bf1cfd07a fix help string for --paste 2012-05-19 10:54:12 +02:00
holger krekel
51d94a4a6e use higher difference on timing 2012-05-18 13:56:49 +02:00
holger krekel
e18abfd013 fix issue143 - call unconfigure/sessionfinish always when
configure/sessionstart where called

use exitcode 4 (instead of 3 which signaled an internal error)
when an initial directory/file was not found
2012-05-17 23:11:23 +02:00
holger krekel
6c7ea8191f fix wrong release version 2012-05-17 15:44:18 +02:00
holger krekel
329dca42a7 add release announcement 2012-05-17 15:25:58 +02:00
holger krekel
0362aaba5a require py-1.4.8 2012-05-17 08:47:50 +02:00
holger krekel
948dea8bb4 bump version to next release 2012-05-17 08:46:49 +02:00
Ronny Pfannschmidt
6155e9139d hande the trial todo class by using repr 2012-05-10 01:38:13 +02:00
holger krekel
6dd8405aed bump version 2012-05-10 00:34:47 +02:00
Ronny Pfannschmidt
c076f4e789 switch pastebin to bpaste.net, fixes #141 2012-05-08 16:13:25 +02:00
Ronny Pfannschmidt
d32a132b51 add the fix for issue 140 to CHANGELOG 2012-05-08 14:15:23 +02:00
Ronny Pfannschmidt
0e3779b14f strip bound wrappers of class setup/tardown, fixes #140
on python3 im_func is replaced by __func__
2012-05-06 23:03:16 +02:00
Benjamin Peterson
fe1c35f8d0 prepend the assertion rewriting hook, so as not to break when builtin import is explicitly on sys.meta_path 2012-05-05 17:31:05 -04:00
Benjamin Peterson
b4588f1798 escape the % operator in string formatting 2012-05-03 13:49:30 -04:00
Benjamin Peterson
64c7c1be15 use non-hacky dynamic package import method 2012-04-27 17:51:50 -04:00
Benjamin Peterson
1c817aa7bd don't use octal syntax, since its not py2/py3 compatible 2012-04-18 11:26:44 -04:00
Ronny Pfannschmidt
d02eaa8881 fix a import strange loop that affects pypy test appsupport on python2.5 2012-04-13 12:41:02 +02:00
holger krekel
b92176024c write down some thoughts on parametrization - still not completely clear what the next stage should look like ... 2012-03-31 10:01:03 -07:00
holger krekel
1c746e0819 merge 2012-03-31 10:12:11 -07:00
Ronny Pfannschmidt
166aae4418 word change in the docs fixes #130 2012-03-22 08:26:37 +01:00
holger krekel
58933aac2a try to better handle @unittest.expectedFailure decorator 2012-03-19 22:53:52 -07:00
Benjamin Peterson
45aa4e5229 remove unused import 2012-03-19 20:04:55 -04:00
holger krekel
e643e99586 bump version number to dev version 2012-03-19 08:53:08 -07:00
holger krekel
9f6d6f630d walk through issues 2012-03-19 06:56:35 -07:00
Ronny Pfannschmidt
812ba87f37 add acomment so highlighting won\'t fail 2012-03-15 15:22:13 +01:00
Ronny Pfannschmidt
2b0887fa5f document integration with setuptools/distribute test command and tests_require 2012-03-15 15:15:21 +01:00
Ronny Pfannschmidt
ee8d2f9950 junitxml: use a exclusive match on the legal ranges of xml for binary escaping, fixes issue 126 2012-03-09 13:12:18 +01:00
holger krekel
51d29cf4c6 mention 2.2.3 in 2.2.2 release announce 2012-02-05 23:54:20 -05:00
holger krekel
e378496b24 Added tag 2.2.3 for changeset 3c11c5c9776f 2012-02-05 23:39:00 -05:00
holger krekel
4d21274a29 release 2.2.3 to fix package contents (2.2.2 contained too many files) 2012-02-05 23:38:31 -05:00
holger krekel
705442cf4e Added tag 2.2.2 for changeset 92b916483c1e 2012-02-05 18:37:31 -05:00
319 changed files with 25771 additions and 5666 deletions

33
.gitignore vendored Normal file
View File

@@ -0,0 +1,33 @@
# Automatically generated by `hgimportsvn`
.svn
.hgsvn
# Ignore local virtualenvs
lib/
bin/
include/
.Python/
# These lines are suggested according to the svn:ignore property
# Feel free to enable them by uncommenting them
*.pyc
*.pyo
*.swp
*.html
*.class
*.orig
*~
doc/*/_build
build/
dist/
*.egg-info
issue/
env/
3rdparty/
.tox
.cache
.coverage
.ropeproject
.idea

View File

@@ -1,9 +1,15 @@
# Automatically generated by `hgimportsvn`
syntax:glob
.svn
.hgsvn
# Ignore local virtualenvs
syntax:glob
lib/
bin/
include/
.Python/
# These lines are suggested according to the svn:ignore property
# Feel free to enable them by uncommenting them
syntax:glob
@@ -15,7 +21,7 @@ syntax:glob
*.orig
*~
doc/_build
doc/*/_build
build/
dist/
*.egg-info
@@ -23,3 +29,7 @@ issue/
env/
3rdparty/
.tox
.cache
.coverage
.ropeproject
*.sublime-*

16
.hgtags
View File

@@ -46,3 +46,19 @@ e5e1746a197f0398356a43fbe2eebac9690f795d 2.1.0
12a05d59249f80276e25fd8b96e8e545b1332b7a 2.1.3
1522710369337d96bf9568569d5f0ca9b38a74e0 2.2.0
3da8cec6c5326ed27c144c9b6d7a64a648370005 2.2.1
92b916483c1e65a80dc80e3f7816b39e84b36a4d 2.2.2
3c11c5c9776f3c678719161e96cc0a08169c1cb8 2.2.3
ad9fe504a371ad8eb613052d58f229aa66f53527 2.2.4
c27a60097767c16a54ae56d9669a77925b213b9b 2.3.0
acf0e1477fb19a1d35a4e40242b77fa6af32eb17 2.3.1
8738b828dec53937765db71951ef955cca4c51f6 2.3.2
7fe44182c434f8ac89149a3c340479872a5d5ccb 2.3.3
ef299e57f24218dbdd949498d7e660723636bcc3 2.3.4
fc3a793e87ec907000a47ea0d3a372a2fe218c0a 2.3.5
b93ac0cdae02effaa3c136a681cc45bba757fe46 1.4.14
b93ac0cdae02effaa3c136a681cc45bba757fe46 1.4.14
0000000000000000000000000000000000000000 1.4.14
0000000000000000000000000000000000000000 1.4.14
0000000000000000000000000000000000000000 1.4.14
af860de70cc3f157ac34ca1d4bf557a057bff775 2.4.0
8828c924acae0b4cad2e2cb92943d51da7cb744a 2.4.1

10
.travis.yml Normal file
View File

@@ -0,0 +1,10 @@
language: python
# command to install dependencies
install: "pip install -U detox"
# # command to run tests
script: detox --recreate
notifications:
irc:
- "chat.freenode.net#pytest-dev"
email:
- pytest-commit@python.org

12
AUTHORS
View File

@@ -6,9 +6,15 @@ Contributors include::
Ronny Pfannschmidt
Benjamin Peterson
Floris Bruynooghe
Jason R. Coombs
Wouter van Ackooy
Samuele Pedroni
Anatoly Bubenkoff
Brianna Laugher
Carl Friedrich Bolz
Armin Rigo
Maho
Jaap Broekhuizen
Maciek Fijalkowski
Guido Wesdorp
Brian Dorsey
@@ -23,3 +29,9 @@ Grig Gheorghiu
Bob Ippolito
Christian Tismer
Daniel Nuri
Graham Horler
Andreas Zeidler
Brian Okken
Katarzyna Jachim
Christian Theunert
Anthon van der Neut

480
CHANGELOG
View File

@@ -1,3 +1,483 @@
Changes between 2.4.1 and 2.4.2
-----------------------------------
- on Windows require colorama and a newer py lib so that py.io.TerminalWriter()
now uses colorama instead of its own ctypes hacks. (fixes issue365)
thanks Paul Moore for bringing it up.
- fix "-k" matching of tests where "repr" and "attr" and other names would
cause wrong matches because of an internal implementation quirk
(don't ask) which is now properly implemented. fixes issue345.
- avoid tmpdir fixture to create too long filenames especially
when parametrization is used (issue354)
- fix pytest-pep8 and pytest-flakes / pytest interactions
(collection names in mark plugin was assuming an item always
has a function which is not true for those plugins etc.)
Thanks Andi Zeidler.
- introduce node.get_marker/node.add_marker API for plugins
like pytest-pep8 and pytest-flakes to avoid the messy
details of the node.keywords pseudo-dicts. Adapated
docs.
- remove attempt to "dup" stdout at startup as it's icky.
the normal capturing should catch enough possibilities
of tests messing up standard FDs.
- add pluginmanager.do_configure(config) as a link to
config.do_configure() for plugin-compatibility
Changes between 2.4.0 and 2.4.1
-----------------------------------
- When using parser.addoption() unicode arguments to the
"type" keyword should also be converted to the respective types.
thanks Floris Bruynooghe, @dnozay. (fixes issue360 and issue362)
- fix dotted filename completion when using argcomplete
thanks Anthon van der Neuth. (fixes issue361)
- fix regression when a 1-tuple ("arg",) is used for specifying
parametrization (the values of the parametrization were passed
nested in a tuple). Thanks Donald Stufft.
- merge doc typo fixes, thanks Andy Dirnberger
Changes between 2.3.5 and 2.4
-----------------------------------
known incompatibilities:
- if calling --genscript from python2.7 or above, you only get a
standalone script which works on python2.7 or above. Use Python2.6
to also get a python2.5 compatible version.
- all xunit-style teardown methods (nose-style, pytest-style,
unittest-style) will not be called if the corresponding setup method failed,
see issue322 below.
- the pytest_plugin_unregister hook wasn't ever properly called
and there is no known implementation of the hook - so it got removed.
- pytest.fixture-decorated functions cannot be generators (i.e. use
yield) anymore. This change might be reversed in 2.4.1 if it causes
unforeseen real-life issues. However, you can always write and return
an inner function/generator and change the fixture consumer to iterate
over the returned generator. This change was done in lieu of the new
``pytest.yield_fixture`` decorator, see below.
new features:
- experimentally introduce a new ``pytest.yield_fixture`` decorator
which accepts exactly the same parameters as pytest.fixture but
mandates a ``yield`` statement instead of a ``return statement`` from
fixture functions. This allows direct integration with "with-style"
context managers in fixture functions and generally avoids registering
of finalization callbacks in favour of treating the "after-yield" as
teardown code. Thanks Andreas Pelme, Vladimir Keleshev, Floris
Bruynooghe, Ronny Pfannschmidt and many others for discussions.
- allow boolean expression directly with skipif/xfail
if a "reason" is also specified. Rework skipping documentation
to recommend "condition as booleans" because it prevents surprises
when importing markers between modules. Specifying conditions
as strings will remain fully supported.
- reporting: color the last line red or green depending if
failures/errors occured or everything passed. thanks Christian
Theunert.
- make "import pdb ; pdb.set_trace()" work natively wrt capturing (no
"-s" needed anymore), making ``pytest.set_trace()`` a mere shortcut.
- fix issue181: --pdb now also works on collect errors (and
on internal errors) . This was implemented by a slight internal
refactoring and the introduction of a new hook
``pytest_exception_interact`` hook (see next item).
- fix issue341: introduce new experimental hook for IDEs/terminals to
intercept debugging: ``pytest_exception_interact(node, call, report)``.
- new monkeypatch.setattr() variant to provide a shorter
invocation for patching out classes/functions from modules:
monkeypatch.setattr("requests.get", myfunc)
will replace the "get" function of the "requests" module with ``myfunc``.
- fix issue322: tearDownClass is not run if setUpClass failed. Thanks
Mathieu Agopian for the initial fix. Also make all of pytest/nose
finalizer mimick the same generic behaviour: if a setupX exists and
fails, don't run teardownX. This internally introduces a new method
"node.addfinalizer()" helper which can only be called during the setup
phase of a node.
- simplify pytest.mark.parametrize() signature: allow to pass a
CSV-separated string to specify argnames. For example:
``pytest.mark.parametrize("input,expected", [(1,2), (2,3)])``
works as well as the previous:
``pytest.mark.parametrize(("input", "expected"), ...)``.
- add support for setUpModule/tearDownModule detection, thanks Brian Okken.
- integrate tab-completion on options through use of "argcomplete".
Thanks Anthon van der Neut for the PR.
- change option names to be hyphen-separated long options but keep the
old spelling backward compatible. py.test -h will only show the
hyphenated version, for example "--collect-only" but "--collectonly"
will remain valid as well (for backward-compat reasons). Many thanks to
Anthon van der Neut for the implementation and to Hynek Schlawack for
pushing us.
- fix issue 308 - allow to mark/xfail/skip individual parameter sets
when parametrizing. Thanks Brianna Laugher.
- call new experimental pytest_load_initial_conftests hook to allow
3rd party plugins to do something before a conftest is loaded.
Bug fixes:
- fix issue358 - capturing options are now parsed more properly
by using a new parser.parse_known_args method.
- pytest now uses argparse instead of optparse (thanks Anthon) which
means that "argparse" is added as a dependency if installing into python2.6
environments or below.
- fix issue333: fix a case of bad unittest/pytest hook interaction.
- PR27: correctly handle nose.SkipTest during collection. Thanks
Antonio Cuni, Ronny Pfannschmidt.
- fix issue355: junitxml puts name="pytest" attribute to testsuite tag.
- fix issue336: autouse fixture in plugins should work again.
- fix issue279: improve object comparisons on assertion failure
for standard datatypes and recognise collections.abc. Thanks to
Brianna Laugher and Mathieu Agopian.
- fix issue317: assertion rewriter support for the is_package method
- fix issue335: document py.code.ExceptionInfo() object returned
from pytest.raises(), thanks Mathieu Agopian.
- remove implicit distribute_setup support from setup.py.
- fix issue305: ignore any problems when writing pyc files.
- SO-17664702: call fixture finalizers even if the fixture function
partially failed (finalizers would not always be called before)
- fix issue320 - fix class scope for fixtures when mixed with
module-level functions. Thanks Anatloy Bubenkoff.
- you can specify "-q" or "-qq" to get different levels of "quieter"
reporting (thanks Katarzyna Jachim)
- fix issue300 - Fix order of conftest loading when starting py.test
in a subdirectory.
- fix issue323 - sorting of many module-scoped arg parametrizations
- make sessionfinish hooks execute with the same cwd-context as at
session start (helps fix plugin behaviour which write output files
with relative path such as pytest-cov)
- fix issue316 - properly reference collection hooks in docs
- fix issue 306 - cleanup of -k/-m options to only match markers/test
names/keywords respectively. Thanks Wouter van Ackooy.
- improved doctest counting for doctests in python modules --
files without any doctest items will not show up anymore
and doctest examples are counted as separate test items.
thanks Danilo Bellini.
- fix issue245 by depending on the released py-1.4.14
which fixes py.io.dupfile to work with files with no
mode. Thanks Jason R. Coombs.
- fix junitxml generation when test output contains control characters,
addressing issue267, thanks Jaap Broekhuizen
- fix issue338: honor --tb style for setup/teardown errors as well. Thanks Maho.
- fix issue307 - use yaml.safe_load in example, thanks Mark Eichin.
- better parametrize error messages, thanks Brianna Laugher
- pytest_terminal_summary(terminalreporter) hooks can now use
".section(title)" and ".line(msg)" methods to print extra
information at the end of a test run.
Changes between 2.3.4 and 2.3.5
-----------------------------------
- fix issue169: respect --tb=style with setup/teardown errors as well.
- never consider a fixture function for test function collection
- allow re-running of test items / helps to fix pytest-reruntests plugin
and also help to keep less fixture/resource references alive
- put captured stdout/stderr into junitxml output even for passing tests
(thanks Adam Goucher)
- Issue 265 - integrate nose setup/teardown with setupstate
so it doesnt try to teardown if it did not setup
- issue 271 - dont write junitxml on slave nodes
- Issue 274 - dont try to show full doctest example
when doctest does not know the example location
- issue 280 - disable assertion rewriting on buggy CPython 2.6.0
- inject "getfixture()" helper to retrieve fixtures from doctests,
thanks Andreas Zeidler
- issue 259 - when assertion rewriting, be consistent with the default
source encoding of ASCII on Python 2
- issue 251 - report a skip instead of ignoring classes with init
- issue250 unicode/str mixes in parametrization names and values now works
- issue257, assertion-triggered compilation of source ending in a
comment line doesn't blow up in python2.5 (fixed through py>=1.4.13.dev6)
- fix --genscript option to generate standalone scripts that also
work with python3.3 (importer ordering)
- issue171 - in assertion rewriting, show the repr of some
global variables
- fix option help for "-k"
- move long description of distribution into README.rst
- improve docstring for metafunc.parametrize()
- fix bug where using capsys with pytest.set_trace() in a test
function would break when looking at capsys.readouterr()
- allow to specify prefixes starting with "_" when
customizing python_functions test discovery. (thanks Graham Horler)
- improve PYTEST_DEBUG tracing output by puting
extra data on a new lines with additional indent
- ensure OutcomeExceptions like skip/fail have initialized exception attributes
- issue 260 - don't use nose special setup on plain unittest cases
- fix issue134 - print the collect errors that prevent running specified test items
- fix issue266 - accept unicode in MarkEvaluator expressions
Changes between 2.3.3 and 2.3.4
-----------------------------------
- yielded test functions will now have autouse-fixtures active but
cannot accept fixtures as funcargs - it's anyway recommended to
rather use the post-2.0 parametrize features instead of yield, see:
http://pytest.org/latest/example/parametrize.html
- fix autouse-issue where autouse-fixtures would not be discovered
if defined in a a/conftest.py file and tests in a/tests/test_some.py
- fix issue226 - LIFO ordering for fixture teardowns
- fix issue224 - invocations with >256 char arguments now work
- fix issue91 - add/discuss package/directory level setups in example
- allow to dynamically define markers via
item.keywords[...]=assignment integrating with "-m" option
- make "-k" accept an expressions the same as with "-m" so that one
can write: -k "name1 or name2" etc. This is a slight incompatibility
if you used special syntax like "TestClass.test_method" which you now
need to write as -k "TestClass and test_method" to match a certain
method in a certain test class.
Changes between 2.3.2 and 2.3.3
-----------------------------------
- fix issue214 - parse modules that contain special objects like e. g.
flask's request object which blows up on getattr access if no request
is active. thanks Thomas Waldmann.
- fix issue213 - allow to parametrize with values like numpy arrays that
do not support an __eq__ operator
- fix issue215 - split test_python.org into multiple files
- fix issue148 - @unittest.skip on classes is now recognized and avoids
calling setUpClass/tearDownClass, thanks Pavel Repin
- fix issue209 - reintroduce python2.4 support by depending on newer
pylib which re-introduced statement-finding for pre-AST interpreters
- nose support: only call setup if its a callable, thanks Andrew
Taumoefolau
- fix issue219 - add py2.4-3.3 classifiers to TROVE list
- in tracebacks *,** arg values are now shown next to normal arguments
(thanks Manuel Jacob)
- fix issue217 - support mock.patch with pytest's fixtures - note that
you need either mock-1.0.1 or the python3.3 builtin unittest.mock.
- fix issue127 - improve documentation for pytest_addoption() and
add a ``config.getoption(name)`` helper function for consistency.
Changes between 2.3.1 and 2.3.2
-----------------------------------
- fix issue208 and fix issue29 use new py version to avoid long pauses
when printing tracebacks in long modules
- fix issue205 - conftests in subdirs customizing
pytest_pycollect_makemodule and pytest_pycollect_makeitem
now work properly
- fix teardown-ordering for parametrized setups
- fix issue127 - better documentation for pytest_addoption
and related objects.
- fix unittest behaviour: TestCase.runtest only called if there are
test methods defined
- improve trial support: don't collect its empty
unittest.TestCase.runTest() method
- "python setup.py test" now works with pytest itself
- fix/improve internal/packaging related bits:
- exception message check of test_nose.py now passes on python33 as well
- issue206 - fix test_assertrewrite.py to work when a global
PYTHONDONTWRITEBYTECODE=1 is present
- add tox.ini to pytest distribution so that ignore-dirs and others config
bits are properly distributed for maintainers who run pytest-own tests
Changes between 2.3.0 and 2.3.1
-----------------------------------
- fix issue202 - fix regression: using "self" from fixture functions now
works as expected (it's the same "self" instance that a test method
which uses the fixture sees)
- skip pexpect using tests (test_pdb.py mostly) on freebsd* systems
due to pexpect not supporting it properly (hanging)
- link to web pages from --markers output which provides help for
pytest.mark.* usage.
Changes between 2.2.4 and 2.3.0
-----------------------------------
- fix issue202 - better automatic names for parametrized test functions
- fix issue139 - introduce @pytest.fixture which allows direct scoping
and parametrization of funcarg factories.
- fix issue198 - conftest fixtures were not found on windows32 in some
circumstances with nested directory structures due to path manipulation issues
- fix issue193 skip test functions with were parametrized with empty
parameter sets
- fix python3.3 compat, mostly reporting bits that previously depended
on dict ordering
- introduce re-ordering of tests by resource and parametrization setup
which takes precedence to the usual file-ordering
- fix issue185 monkeypatching time.time does not cause pytest to fail
- fix issue172 duplicate call of pytest.fixture decoratored setup_module
functions
- fix junitxml=path construction so that if tests change the
current working directory and the path is a relative path
it is constructed correctly from the original current working dir.
- fix "python setup.py test" example to cause a proper "errno" return
- fix issue165 - fix broken doc links and mention stackoverflow for FAQ
- catch unicode-issues when writing failure representations
to terminal to prevent the whole session from crashing
- fix xfail/skip confusion: a skip-mark or an imperative pytest.skip
will now take precedence before xfail-markers because we
can't determine xfail/xpass status in case of a skip. see also:
http://stackoverflow.com/questions/11105828/in-py-test-when-i-explicitly-skip-a-test-that-is-marked-as-xfail-how-can-i-get
- always report installed 3rd party plugins in the header of a test run
- fix issue160: a failing setup of an xfail-marked tests should
be reported as xfail (not xpass)
- fix issue128: show captured output when capsys/capfd are used
- fix issue179: propperly show the dependency chain of factories
- pluginmanager.register(...) now raises ValueError if the
plugin has been already registered or the name is taken
- fix issue159: improve http://pytest.org/latest/faq.html
especially with respect to the "magic" history, also mention
pytest-django, trial and unittest integration.
- make request.keywords and node.keywords writable. All descendant
collection nodes will see keyword values. Keywords are dictionaries
containing markers and other info.
- fix issue 178: xml binary escapes are now wrapped in py.xml.raw
- fix issue 176: correctly catch the builtin AssertionError
even when we replaced AssertionError with a subclass on the
python level
- factory discovery no longer fails with magic global callables
that provide no sane __code__ object (mock.call for example)
- fix issue 182: testdir.inprocess_run now considers passed plugins
- fix issue 188: ensure sys.exc_info is clear on python2
before calling into a test
- fix issue 191: add unittest TestCase runTest method support
- fix issue 156: monkeypatch correctly handles class level descriptors
- reporting refinements:
- pytest_report_header now receives a "startdir" so that
you can use startdir.bestrelpath(yourpath) to show
nice relative path
- allow plugins to implement both pytest_report_header and
pytest_sessionstart (sessionstart is invoked first).
- don't show deselected reason line if there is none
- py.test -vv will show all of assert comparisations instead of truncating
Changes between 2.2.3 and 2.2.4
-----------------------------------
- fix error message for rewritten assertions involving the % operator
- fix issue 126: correctly match all invalid xml characters for junitxml
binary escape
- fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions
of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called
- fix issue #144: better mangle test ids to junitxml classnames
- upgrade distribute_setup.py to 0.6.27
Changes between 2.2.2 and 2.2.3
----------------------------------------
- fix uploaded package to only include neccesary files
Changes between 2.2.1 and 2.2.2
----------------------------------------

View File

@@ -1,23 +1,83 @@
refine parametrize API in 2.2 series
recorder = monkeypatch.function(".......")
-------------------------------------------------------------
tags: critical feature 2.2
tags: nice feature
extend metafunc.parametrize to better support indirection
by specifying a setupfunc(request, val) which will _substitute_
the funcarg factory. Here is an example:
Like monkeypatch.replace but sets a mock-like call recorder:
def setupdb(request, val):
recorder = monkeypatch.function("os.path.abspath")
recorder.set_return("/hello")
os.path.abspath("hello")
call, = recorder.calls
assert call.args.path == "hello"
assert call.returned == "/hello"
...
Unlike mock, "args.path" acts on the parsed auto-spec'ed ``os.path.abspath``
so it's independent from if the client side called "os.path.abspath(path=...)"
or "os.path.abspath('positional')".
refine parametrize API
-------------------------------------------------------------
tags: critical feature
extend metafunc.parametrize to directly support indirection, example:
def setupdb(request, config):
# setup "resource" based on test request and the values passed
# in to parametrize. setupfunc is called for each such value.
# you may use request.addfinalizer() or request.cached_setup ...
return db
return dynamic_setup_database(val)
@pytest.mark.parametrize("db", ["pg", "mysql"], setupfunc=setupdb)
def test_heavy_functional_test(db):
...
There would be no need to write funcarg factories for this example, only
to explain the attributes and functionality of "request".
There would be no need to write or explain funcarg factories and
their special __ syntax.
The examples and improvements should also show how to put the parametrize
decorator to a class, to a module or even to a directory. For the directory
part a conftest.py content like this::
pytestmark = [
@pytest.mark.parametrize_setup("db", ...),
]
probably makes sense in order to keep the declarative nature. This mirrors
the marker-mechanism with respect to a test module but puts it to a directory
scale.
When doing larger scoped parametrization it probably becomes neccessary
to allow parametrization to be ignored if the according parameter is not
used (currently any parametrized argument that is not present in a function will cause a ValueError). Example:
@pytest.mark.parametrize("db", ..., mustmatch=False)
means to not raise an error but simply ignore the parametrization
if the signature of a decorated function does not match. XXX is it
not sufficient to always allow non-matches?
allow parametrized attributes on classes
--------------------------------------------------
tags: wish 2.4
example:
@pytest.mark.parametrize_attr("db", setupfunc, [1,2,3], scope="class")
@pytest.mark.parametrize_attr("tmp", setupfunc, scope="...")
class TestMe:
def test_hello(self):
access self.db ...
this would run the test_hello() function three times with three
different values for self.db. This could also work with unittest/nose
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
---------------------------------------------------------------
@@ -46,36 +106,10 @@ appropriately to avoid this issue. Moreover/Alternatively, we could
record which implementations of a hook succeeded and only call their
teardown.
do early-teardown of test modules
-----------------------------------------
tags: feature 2.3
currently teardowns are called when the next tests is setup
except for the function/method level where interally
"teardown_exact" tears down immediately. Generalize
this to perform the "neccessary" teardown compared to
the "next" test item during teardown - this should
get rid of some irritations because otherwise e.g.
prints of teardown-code appear in the setup of the next test.
consider and document __init__ file usage in test directories
---------------------------------------------------------------
tags: bug 2.3 core
Currently, a test module is imported with its fully qualified
package path, determined by checking __init__ files upwards.
This has the side effect that a source package at the root
of the test dir could be imported as well. This is somewhat
convenient but complicates the picture for running tests against
different versions of a package. Also, implicit sys.path
manipulations are problematic per-se. Maybe factorting out
a pytest_addsyspath hook which can be disabled from the command line
makes sense. In any case documentation/recommendations for
certain scenarios makes sense.
relax requirement to have tests/testing contain an __init__
----------------------------------------------------------------
tags: feature 2.3
tags: feature
bb: http://bitbucket.org/hpk42/py-trunk/issue/64
A local test run of a "tests" directory may work
@@ -86,7 +120,7 @@ i.e. port the nose-logic of unloading a test module.
customize test function collection
-------------------------------------------------------
tags: feature 2.3
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
@@ -95,7 +129,7 @@ tags: feature 2.3
introduce pytest.mark.importorskip
-------------------------------------------------------
tags: feature 2.3
tags: feature
in addition to the imperative pytest.importorskip also introduce
a pytest.mark.importorskip so that the test count is more correct.
@@ -103,7 +137,7 @@ a pytest.mark.importorskip so that the test count is more correct.
introduce py.test.mark.platform
-------------------------------------------------------
tags: feature 2.3
tags: feature
Introduce nice-to-spell platform-skipping, examples:
@@ -120,7 +154,7 @@ interpreter versions.
pytest.mark.xfail signature change
-------------------------------------------------------
tags: feature 2.3
tags: feature
change to pytest.mark.xfail(reason, (optional)condition)
to better implement the word meaning. It also signals
@@ -128,36 +162,28 @@ better that we always have some kind of an implementation
reason that can be formualated.
Compatibility? how to introduce a new name/keep compat?
introduce py.test.mark registration
-----------------------------------------
tags: feature 2.3
introduce a hook that allows to register a named mark decorator
with documentation and add "py.test --marks" to get
a list of available marks. Deprecate "dynamic" mark
definitions.
allow to non-intrusively apply skipfs/xfail/marks
---------------------------------------------------
tags: feature 2.3
tags: feature
use case: mark a module or directory structures
to be skipped on certain platforms (i.e. no import
attempt will be made).
consider introducing a hook/mechanism that allows to apply marks
from conftests or plugins.
from conftests or plugins. (See extended parametrization)
explicit referencing of conftest.py files
-----------------------------------------
tags: feature 2.3
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
----------------------------------
tags: feature 2.3
tags: feature
introduce more declarative configuration options:
- (to-be-collected test directories)
@@ -168,7 +194,7 @@ introduce more declarative configuration options:
new documentation
----------------------------------
tags: feature 2.3
tags: feature
- logo py.test
- examples for unittest or functional testing
@@ -177,55 +203,25 @@ tags: feature 2.3
have imported module mismatch honour relative paths
--------------------------------------------------------
tags: bug 2.3
tags: bug
With 1.1.1 py.test fails at least on windows if an import
is relative and compared against an absolute conftest.py
path. Normalize.
call termination with small timeout
-------------------------------------------------
tags: feature 2.3
test: testing/pytest/dist/test_dsession.py - test_terminate_on_hanging_node
Call gateway group termination with a small timeout if available.
Should make dist-testing less likely to leave lost processes.
consider globals: py.test.ensuretemp and config
--------------------------------------------------------------
tags: experimental-wish 2.3
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
a plugin rather than being there from the start.
consider allowing funcargs for setup methods
--------------------------------------------------------------
tags: experimental-wish 2.3
Users have expressed the wish to have funcargs available to setup
functions. Experiment with allowing funcargs there - it might
also help to make the py.test.ensuretemp and config deprecation.
For filling funcargs for setup methods, we could call funcarg
factories with a request object that not have a cls/function
attributes. However, how to handle parametrized test functions
and funcargs?
maybe introduce a setup method like:
setup_invocation(self, request)
which has full access to the test invocation through "request"
through which you can get funcargvalues, use cached_setup etc.
Therefore, the access to funcargs would be indirect but it
could be consistently implemented. setup_invocation() would
be a "glue" function for bringing together the xUnit and funcargs
world.
consider pytest_addsyspath hook
-----------------------------------------
tags: 2.3
tags: wish
py.test could call a new pytest_addsyspath() in order to systematically
allow manipulation of sys.path and to inhibit it via --no-addsyspath
@@ -235,17 +231,10 @@ Alternatively it could also be done via the config object
and pytest_configure.
show plugin information in test header
----------------------------------------------------------------
tags: feature 2.3
Now that external plugins are becoming more numerous
it would be useful to have external plugins along with
their versions displayed as a header line.
deprecate global py.test.config usage
----------------------------------------------------------------
tags: feature 2.3
tags: feature
py.test.ensuretemp and py.test.config are probably the last
objects containing global state. Often using them is not
@@ -255,7 +244,7 @@ as others.
remove deprecated bits in collect.py
-------------------------------------------------------------------
tags: feature 2.3
tags: feature
In an effort to further simplify code, review and remove deprecated bits
in collect.py. Probably good:
@@ -264,7 +253,7 @@ in collect.py. Probably good:
implement fslayout decorator
---------------------------------
tags: feature 2.3
tags: feature
Improve the way how tests can work with pre-made examples,
keeping the layout close to the test function:
@@ -278,9 +267,107 @@ keeping the layout close to the test function:
pass
""")
def test_run(pytester, fslayout):
p = fslayout.find("test_*.py")
p = fslayout.findone("test_*.py")
result = pytester.runpytest(p)
assert result.ret == 0
assert result.passed == 1
Another idea is to allow to define a full scenario including the run
in one content string::
runscenario("""
test_{TESTNAME}.py:
import pytest
@pytest.mark.xfail
def test_that_fails():
assert 0
@pytest.mark.skipif("True")
def test_hello():
pass
conftest.py:
import pytest
def pytest_runsetup_setup(item):
pytest.skip("abc")
runpytest -rsxX
*SKIP*{TESTNAME}*
*1 skipped*
""")
This could be run with at least three different ways to invoke pytest:
through the shell, through "python -m pytest" and inlined. As inlined
would be the fastest it could be run first (or "--fast" mode).
Create isolate plugin
---------------------
tags: feature
The idea is that you can e.g. import modules in a test and afterwards
sys.modules, sys.meta_path etc would be reverted. It can go further
then just importing however, e.g. current working direcroty, file
descriptors, ...
This would probably be done by marking::
@pytest.mark.isolate(importing=True, cwd=True, fds=False)
def test_foo():
...
With the possibility of doing this globally in an ini-file.
fnmatch for test names
----------------------
tags: feature-wish
various testsuites use suffixes instead of prefixes for test classes
also it lends itself to bdd style test names::
class UserBehaviour:
def anonymous_should_not_have_inbox(user):
...
def registred_should_have_inbox(user):
..
using the following in pytest.ini::
[pytest]
python_classes = Test *Behaviour *Test
python_functions = test *_should_*
mechanism for running named parts of tests with different reporting behaviour
------------------------------------------------------------------------------
tags: feature-wish-incomplete
a few use-cases come to mind:
* fail assertions and record that without stopping a complete test
* this is in particular hepfull if a small bit of a test is known to fail/xfail::
def test_fun():
with pytest.section('fdcheck, marks=pytest.mark.xfail_if(...)):
breaks_on_windows()
* divide functional/acceptance tests into sections
* provide a different mechanism for generators, maybe something like::
def pytest_runtest_call(item)
if not generator:
...
prepare_check = GeneratorCheckprepare()
gen = item.obj(**fixtures)
for check in gen
id, call = prepare_check(check)
# bubble should only prevent exception propagation after a failure
# the whole test should still fail
# there might be need for a loer level api and taking custom markers into account
with pytest.section(id, bubble=False):
call()

View File

@@ -1,7 +1,7 @@
include CHANGELOG
include README.txt
include README.rst
include setup.py
include distribute_setup.py
include tox.ini
include LICENSE
graft doc
graft testing

48
README.rst Normal file
View File

@@ -0,0 +1,48 @@
Changelog: http://pytest.org/latest/changelog.html
The ``py.test`` testing tool makes it easy to write small tests, yet
scales to support complex functional testing. It provides
- `auto-discovery
<http://pytest.org/latest/goodpractises.html#python-test-discovery>`_
of test modules and functions,
- 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
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.
- 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
def test_function():
i = 4
assert i == 3
which can be run with ``py.test test_module.py``. See `getting-started <http://pytest.org/latest/getting-started.html#our-first-test-run>`_ for more examples.
For much more info, including PDF docs, see
http://pytest.org
and report bugs at:
http://bitbucket.org/hpk42/pytest/issues/
and checkout repos at:
http://github.com/hpk42/pytest/ (mirror)
http://bitbucket.org/hpk42/pytest/
Copyright Holger Krekel and others, 2004-2013
Licensed under the MIT license.

View File

@@ -1,4 +0,0 @@
py.test is a simple and popular testing tool for Python.
See http://pytest.org for more documentation.

View File

@@ -1,2 +1,2 @@
#
__version__ = '2.2.2'
__version__ = '2.4.2'

104
_pytest/_argcomplete.py Normal file
View File

@@ -0,0 +1,104 @@
"""allow bash-completion for argparse with argcomplete if installed
needs argcomplete>=0.5.6 for python 3.2/3.3 (older versions fail
to find the magic string, so _ARGCOMPLETE env. var is never set, and
this does not need special code.
argcomplete does not support python 2.5 (although the changes for that
are minor).
Function try_argcomplete(parser) should be called directly before
the call to ArgumentParser.parse_args().
The filescompleter is what you normally would use on the positional
arguments specification, in order to get "dirname/" after "dirn<TAB>"
instead of the default "dirname ":
optparser.add_argument(Config._file_or_dir, nargs='*'
).completer=filescompleter
Other, application specific, completers should go in the file
doing the add_argument calls as they need to be specified as .completer
attributes as well. (If argcomplete is not installed, the function the
attribute points to will not be used).
SPEEDUP
=======
The generic argcomplete script for bash-completion
(/etc/bash_completion.d/python-argcomplete.sh )
uses a python program to determine startup script generated by pip.
You can speed up completion somewhat by changing this script to include
# PYTHON_ARGCOMPLETE_OK
so the the python-argcomplete-check-easy-install-script does not
need to be called to find the entry point of the code and see if that is
marked with PYTHON_ARGCOMPLETE_OK
INSTALL/DEBUGGING
=================
To include this support in another application that has setup.py generated
scripts:
- add the line:
# PYTHON_ARGCOMPLETE_OK
near the top of the main python entry point
- include in the file calling parse_args():
from _argcomplete import try_argcomplete, filescompleter
, call try_argcomplete just before parse_args(), and optionally add
filescompleter to the positional arguments' add_argument()
If things do not work right away:
- switch on argcomplete debugging with (also helpful when doing custom
completers):
export _ARC_DEBUG=1
- run:
python-argcomplete-check-easy-install-script $(which appname)
echo $?
will echo 0 if the magic line has been found, 1 if not
- sometimes it helps to find early on errors using:
_ARGCOMPLETE=1 _ARC_DEBUG=1 appname
which should throw a KeyError: 'COMPLINE' (which is properly set by the
global argcomplete script).
"""
import sys
import os
from glob import glob
class FastFilesCompleter:
'Fast file completer class'
def __init__(self, directories=True):
self.directories = directories
def __call__(self, prefix, **kwargs):
"""only called on non option completions"""
if os.path.sep in prefix[1:]: #
prefix_dir = len(os.path.dirname(prefix) + os.path.sep)
else:
prefix_dir = 0
completion = []
globbed = []
if '*' not in prefix and '?' not in prefix:
if prefix[-1] == os.path.sep: # we are on unix, otherwise no bash
globbed.extend(glob(prefix + '.*'))
prefix += '*'
globbed.extend(glob(prefix))
for x in sorted(globbed):
if os.path.isdir(x):
x += '/'
# append stripping the prefix (like bash, not like compgen)
completion.append(x[prefix_dir:])
return completion
if os.environ.get('_ARGCOMPLETE'):
# argcomplete 0.5.6 is not compatible with python 2.5.6: print/with/format
if sys.version_info[:2] < (2, 6):
sys.exit(1)
try:
import argcomplete.completers
except ImportError:
sys.exit(-1)
filescompleter = FastFilesCompleter()
def try_argcomplete(parser):
argcomplete.autocomplete(parser)
else:
def try_argcomplete(parser): pass
filescompleter = None

View File

@@ -3,7 +3,6 @@ support for presenting detailed information in failing assertions.
"""
import py
import sys
import pytest
from _pytest.monkeypatch import monkeypatch
from _pytest.assertion import util
@@ -19,8 +18,8 @@ def pytest_addoption(parser):
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', action="store_true", default=False,
dest="nomagic", 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."""
@@ -39,7 +38,10 @@ def pytest_configure(config):
except ImportError:
mode = "reinterp"
else:
if sys.platform.startswith('java'):
# 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)):
mode = "reinterp"
if mode != "plain":
_load_modules(mode)
@@ -50,7 +52,7 @@ def pytest_configure(config):
hook = None
if mode == "rewrite":
hook = rewrite.AssertionRewritingHook()
sys.meta_path.append(hook)
sys.meta_path.insert(0, hook)
warn_about_missing_assertion(mode)
config._assertstate = AssertionState(config, mode)
config._assertstate.hook = hook
@@ -73,8 +75,12 @@ def pytest_runtest_setup(item):
def callbinrepr(op, left, right):
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(''.join(new_expl[1:])) > 80*8 and item.config.option.verbose < 2:
new_expl[1:] = ['Detailed information truncated, use "-vv" to see']
res = '\n~'.join(new_expl)
if item.config.getvalue("assertmode") == "rewrite":
# The result will be fed back a python % formatting

View File

@@ -11,7 +11,7 @@ from _pytest.assertion import util
from _pytest.assertion.reinterpret import BuiltinAssertionError
if sys.platform.startswith("java") and sys.version_info < (2, 5, 2):
if sys.platform.startswith("java"):
# See http://bugs.jython.org/issue1497
_exprs = ("BoolOp", "BinOp", "UnaryOp", "Lambda", "IfExp", "Dict",
"ListComp", "GeneratorExp", "Yield", "Compare", "Call",

View File

@@ -1,8 +1,7 @@
import py
import sys, inspect
from compiler import parse, ast, pycodegen
from _pytest.assertion.util import format_explanation
from _pytest.assertion.reinterpret import BuiltinAssertionError
from _pytest.assertion.util import format_explanation, BuiltinAssertionError
passthroughex = py.builtin._sysex
@@ -527,10 +526,13 @@ if __name__ == '__main__':
# example:
def f():
return 5
def g():
return 3
def h(x):
return 'never'
check("f() * g() == 5")
check("not f()")
check("not (f() and g() or 0)")

View File

@@ -1,7 +1,6 @@
import sys
import py
BuiltinAssertionError = py.builtin.builtins.AssertionError
from _pytest.assertion.util import BuiltinAssertionError
class AssertionError(BuiltinAssertionError):
def __init__(self, *args):
@@ -45,4 +44,3 @@ if sys.version_info >= (2, 6) or (sys.platform.startswith("java")):
from _pytest.assertion.newinterpret import interpret as reinterpret
else:
reinterpret = reinterpret_old

View File

@@ -1,12 +1,12 @@
"""Rewrite assertion AST to produce nice error messages"""
import ast
import collections
import errno
import itertools
import imp
import marshal
import os
import re
import struct
import sys
import types
@@ -15,12 +15,6 @@ import py
from _pytest.assertion import util
# Windows gives ENOENT in places *nix gives ENOTDIR.
if sys.platform.startswith("win"):
PATH_COMPONENT_NOT_DIR = errno.ENOENT
else:
PATH_COMPONENT_NOT_DIR = errno.ENOTDIR
# py.test caches rewritten pycs in __pycache__.
if hasattr(imp, "get_tag"):
PYTEST_TAG = imp.get_tag() + "-PYTEST"
@@ -35,13 +29,14 @@ else:
PYTEST_TAG = "%s-%s%s-PYTEST" % (impl, ver[0], ver[1])
del ver, impl
PYC_EXT = ".py" + "c" if __debug__ else "o"
PYC_EXT = ".py" + (__debug__ and "c" or "o")
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
REWRITE_NEWLINES = sys.version_info[:2] != (2, 7) and sys.version_info < (3, 2)
ASCII_IS_DEFAULT_ENCODING = sys.version_info[0] < 3
class AssertionRewritingHook(object):
"""Import hook which rewrites asserts."""
"""PEP302 Import hook which rewrites asserts."""
def __init__(self):
self.session = None
@@ -96,7 +91,8 @@ class AssertionRewritingHook(object):
finally:
self.session = sess
else:
state.trace("matched test file (was specified on cmdline): %r" % (fn,))
state.trace("matched test file (was specified on cmdline): %r" %
(fn,))
# The requested module looks like a test file, so rewrite it. This is
# the most magical part of the process: load the source, rewrite the
# asserts, and load the rewritten source. We also cache the rewritten
@@ -117,19 +113,19 @@ class AssertionRewritingHook(object):
# common case) or it's blocked by a non-dir node. In the
# latter case, we'll ignore it in _write_pyc.
pass
elif e == PATH_COMPONENT_NOT_DIR:
elif e in [errno.ENOENT, errno.ENOTDIR]:
# One of the path components was not a directory, likely
# because we're in a zip file.
write = False
elif e == errno.EACCES:
state.trace("read only directory: %r" % (fn_pypath.dirname,))
state.trace("read only directory: %r" % fn_pypath.dirname)
write = False
else:
raise
cache_name = fn_pypath.basename[:-3] + PYC_TAIL
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...
# 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)
if co is None:
state.trace("rewriting %r" % (fn,))
@@ -154,27 +150,41 @@ class AssertionRewritingHook(object):
mod.__file__ = co.co_filename
# Normally, this attribute is 3.2+.
mod.__cached__ = pyc
mod.__loader__ = self
py.builtin.exec_(co, mod.__dict__)
except:
del sys.modules[name]
raise
return sys.modules[name]
def _write_pyc(co, source_path, 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.)
def is_package(self, name):
try:
fd, fn, desc = imp.find_module(name)
except ImportError:
return False
if fd is not None:
fd.close()
tp = desc[2]
return tp == imp.PKG_DIRECTORY
def _write_pyc(state, co, source_path, 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:
err = sys.exc_info()[1].errno
if err == PATH_COMPONENT_NOT_DIR:
# This happens when we get a EEXIST in find_module creating the
# __pycache__ directory and __pycache__ is by some non-dir node.
return False
raise
state.trace("error writing pyc file at %s: errno=%s" %(pyc, err))
# we ignore any failure to write the cache file
# there are many reasons, permission-denied, __pycache__ being a
# file etc.
return False
try:
fp.write(imp.get_magic())
fp.write(struct.pack("<l", mtime))
@@ -186,12 +196,43 @@ def _write_pyc(co, source_path, pyc):
RN = "\r\n".encode("utf-8")
N = "\n".encode("utf-8")
cookie_re = re.compile("coding[:=]\s*[-\w.]+")
BOM_UTF8 = '\xef\xbb\xbf'
def _rewrite_test(state, fn):
"""Try to read and rewrite *fn* and return the code object."""
try:
source = fn.read("rb")
except EnvironmentError:
return 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
# outside the ASCII range. Sadly, this behavior does not extend to
# compile() or ast.parse(), which prefer to interpret the bytes as
# latin-1. (At least they properly handle explicit coding cookies.) To
# preserve this error behavior, we could force ast.parse() to use ASCII
# as the encoding by inserting a coding cookie. Unfortunately, that
# messes up line numbers. Thus, we have to check ourselves if anything
# is outside the ASCII range in the case no encoding is explicitly
# declared. For more context, see issue #269. Yay for Python 3 which
# gets this right.
end1 = source.find("\n")
end2 = source.find("\n", end1 + 1)
if (not source.startswith(BOM_UTF8) and
(not cookie_re.match(source[0:end1]) or
not cookie_re.match(source[end1:end2]))):
if hasattr(state, "_indecode"):
return None # encodings imported us again, we don't rewrite
state._indecode = True
try:
try:
source.decode("ascii")
except UnicodeDecodeError:
# Let it fail in real import.
return None
finally:
del state._indecode
# On Python versions which are not 2.7 and less than or equal to 3.1, the
# parser expects *nix newlines.
if REWRITE_NEWLINES:
@@ -217,12 +258,12 @@ def _make_rewritten_pyc(state, fn, pyc, co):
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(co, fn, pyc)
_write_pyc(state, co, fn, 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(co, fn, proc_pyc):
if _write_pyc(state, co, fn, proc_pyc):
os.rename(proc_pyc, pyc)
def _read_pyc(source, pyc):
@@ -241,9 +282,8 @@ def _read_pyc(source, pyc):
except EnvironmentError:
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) != 8 or data[:4] != imp.get_magic() or
struct.unpack("<l", data[4:])[0] != mtime):
return None
co = marshal.load(fp)
if not isinstance(co, types.CodeType):
@@ -262,6 +302,9 @@ def rewrite_asserts(mod):
_saferepr = py.io.saferepr
from _pytest.assertion.util import format_explanation as _format_explanation
def _should_repr_global_name(obj):
return not hasattr(obj, "__name__") and not py.builtin.callable(obj)
def _format_boolop(explanations, is_or):
return "(" + (is_or and " or " or " and ").join(explanations) + ")"
@@ -281,35 +324,35 @@ def _call_reprcompare(ops, results, expls, each_obj):
unary_map = {
ast.Not : "not %s",
ast.Invert : "~%s",
ast.USub : "-%s",
ast.UAdd : "+%s"
ast.Not: "not %s",
ast.Invert: "~%s",
ast.USub: "-%s",
ast.UAdd: "+%s"
}
binop_map = {
ast.BitOr : "|",
ast.BitXor : "^",
ast.BitAnd : "&",
ast.LShift : "<<",
ast.RShift : ">>",
ast.Add : "+",
ast.Sub : "-",
ast.Mult : "*",
ast.Div : "/",
ast.FloorDiv : "//",
ast.Mod : "%",
ast.Eq : "==",
ast.NotEq : "!=",
ast.Lt : "<",
ast.LtE : "<=",
ast.Gt : ">",
ast.GtE : ">=",
ast.Pow : "**",
ast.Is : "is",
ast.IsNot : "is not",
ast.In : "in",
ast.NotIn : "not in"
ast.BitOr: "|",
ast.BitXor: "^",
ast.BitAnd: "&",
ast.LShift: "<<",
ast.RShift: ">>",
ast.Add: "+",
ast.Sub: "-",
ast.Mult: "*",
ast.Div: "/",
ast.FloorDiv: "//",
ast.Mod: "%%", # escaped for string formatting
ast.Eq: "==",
ast.NotEq: "!=",
ast.Lt: "<",
ast.LtE: "<=",
ast.Gt: ">",
ast.GtE: ">=",
ast.Pow: "**",
ast.Is: "is",
ast.IsNot: "is not",
ast.In: "in",
ast.NotIn: "not in"
}
@@ -342,7 +385,7 @@ class AssertionRewriter(ast.NodeVisitor):
lineno = 0
for item in mod.body:
if (expect_docstring and isinstance(item, ast.Expr) and
isinstance(item.value, ast.Str)):
isinstance(item.value, ast.Str)):
doc = item.value.s
if "PYTEST_DONT_REWRITE" in doc:
# The module has disabled assertion rewriting.
@@ -463,7 +506,8 @@ class AssertionRewriter(ast.NodeVisitor):
body.append(raise_)
# Clear temporary variables by setting them to None.
if self.variables:
variables = [ast.Name(name, ast.Store()) for name in self.variables]
variables = [ast.Name(name, ast.Store())
for name in self.variables]
clear = ast.Assign(variables, ast.Name("None", ast.Load()))
self.statements.append(clear)
# Fix line numbers.
@@ -472,11 +516,12 @@ class AssertionRewriter(ast.NodeVisitor):
return self.statements
def visit_Name(self, name):
# Check if the name is local or not.
# Display the repr of the name if it's a local variable or
# _should_repr_global_name() thinks it's acceptable.
locs = ast.Call(self.builtin("locals"), [], [], None, None)
globs = ast.Call(self.builtin("globals"), [], [], None, None)
ops = [ast.In(), ast.IsNot()]
test = ast.Compare(ast.Str(name.id), ops, [locs, globs])
inlocs = ast.Compare(ast.Str(name.id), [ast.In()], [locs])
dorepr = self.helper("should_repr_global_name", name)
test = ast.BoolOp(ast.Or(), [inlocs, dorepr])
expr = ast.IfExp(test, self.display(name), ast.Str(name.id))
return name, self.explanation_param(expr)
@@ -549,7 +594,8 @@ class AssertionRewriter(ast.NodeVisitor):
new_kwarg, expl = self.visit(call.kwargs)
arg_expls.append("**" + expl)
expl = "%s(%s)" % (func_expl, ', '.join(arg_expls))
new_call = ast.Call(new_func, new_args, new_kwargs, new_star, new_kwarg)
new_call = ast.Call(new_func, new_args, new_kwargs,
new_star, new_kwarg)
res = self.assign(new_call)
res_expl = self.explanation_param(self.display(res))
outer_expl = "%s\n{%s = %s\n}" % (res_expl, res_expl, expl)

View File

@@ -1,14 +1,24 @@
"""Utilities for assertion debugging"""
import py
try:
from collections.abc import Sequence
except ImportError:
try:
from collections import Sequence
except ImportError:
Sequence = list
BuiltinAssertionError = py.builtin.builtins.AssertionError
# The _reprcompare attribute on the util module is used by the new assertion
# interpretation code and assertion rewriter to detect this plugin was
# loaded and in turn call the hooks defined here as part of the
# DebugInterpreter.
_reprcompare = None
def format_explanation(explanation):
"""This formats an explanation
@@ -82,87 +92,83 @@ except NameError:
basestring = str
def assertrepr_compare(op, left, right):
"""return specialised explanations for some operators/operands"""
width = 80 - 15 - len(op) - 2 # 15 chars indentation, 1 space around op
def assertrepr_compare(config, op, left, right):
"""Return specialised explanations for some operators/operands"""
width = 80 - 15 - len(op) - 2 # 15 chars indentation, 1 space around op
left_repr = py.io.saferepr(left, maxsize=int(width/2))
right_repr = py.io.saferepr(right, maxsize=width-len(left_repr))
summary = '%s %s %s' % (left_repr, op, right_repr)
issequence = lambda x: isinstance(x, (list, tuple))
issequence = lambda x: (isinstance(x, (list, tuple, Sequence))
and not isinstance(x, basestring))
istext = lambda x: isinstance(x, basestring)
isdict = lambda x: isinstance(x, dict)
isset = lambda x: isinstance(x, set)
isset = lambda x: isinstance(x, (set, frozenset))
verbose = config.getoption('verbose')
explanation = None
try:
if op == '==':
if istext(left) and istext(right):
explanation = _diff_text(left, right)
explanation = _diff_text(left, right, verbose)
elif issequence(left) and issequence(right):
explanation = _compare_eq_sequence(left, right)
explanation = _compare_eq_sequence(left, right, verbose)
elif isset(left) and isset(right):
explanation = _compare_eq_set(left, right)
explanation = _compare_eq_set(left, right, verbose)
elif isdict(left) and isdict(right):
explanation = _diff_text(py.std.pprint.pformat(left),
py.std.pprint.pformat(right))
explanation = _compare_eq_dict(left, right, verbose)
elif op == 'not in':
if istext(left) and istext(right):
explanation = _notin_text(left, right)
explanation = _notin_text(left, right, verbose)
except py.builtin._sysex:
raise
except:
excinfo = py.code.ExceptionInfo()
explanation = ['(pytest_assertion plugin: representation of '
'details failed. Probably an object has a faulty __repr__.)',
str(excinfo)
]
explanation = [
'(pytest_assertion plugin: representation of details failed. '
'Probably an object has a faulty __repr__.)', str(excinfo)]
if not explanation:
return None
# Don't include pageloads of data, should be configurable
if len(''.join(explanation)) > 80*8:
explanation = ['Detailed information too verbose, truncated']
return [summary] + explanation
def _diff_text(left, right):
def _diff_text(left, right, verbose=False):
"""Return the explanation for the diff between text
This will skip leading and trailing characters which are
identical to keep the diff minimal.
Unless --verbose is used this will skip leading and trailing
characters which are identical to keep the diff minimal.
"""
explanation = []
i = 0 # just in case left or right has zero length
for i in range(min(len(left), len(right))):
if left[i] != right[i]:
break
if i > 42:
i -= 10 # Provide some context
explanation = ['Skipping %s identical '
'leading characters in diff' % i]
left = left[i:]
right = right[i:]
if len(left) == len(right):
for i in range(len(left)):
if left[-i] != right[-i]:
if not verbose:
i = 0 # just in case left or right has zero length
for i in range(min(len(left), len(right))):
if left[i] != right[i]:
break
if i > 42:
i -= 10 # Provide some context
explanation += ['Skipping %s identical '
'trailing characters in diff' % i]
left = left[:-i]
right = right[:-i]
i -= 10 # Provide some context
explanation = ['Skipping %s identical leading '
'characters in diff, use -v to show' % i]
left = left[i:]
right = right[i:]
if len(left) == len(right):
for i in range(len(left)):
if left[-i] != right[-i]:
break
if i > 42:
i -= 10 # Provide some context
explanation += ['Skipping %s identical trailing '
'characters in diff, use -v to show' % i]
left = left[:-i]
right = right[:-i]
explanation += [line.strip('\n')
for line in py.std.difflib.ndiff(left.splitlines(),
right.splitlines())]
return explanation
def _compare_eq_sequence(left, right):
def _compare_eq_sequence(left, right, verbose=False):
explanation = []
for i in range(min(len(left), len(right))):
if left[i] != right[i]:
@@ -170,16 +176,18 @@ def _compare_eq_sequence(left, right):
(i, left[i], right[i])]
break
if len(left) > len(right):
explanation += ['Left contains more items, '
'first extra item: %s' % py.io.saferepr(left[len(right)],)]
explanation += [
'Left contains more items, first extra item: %s' %
py.io.saferepr(left[len(right)],)]
elif len(left) < len(right):
explanation += ['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))
explanation += [
'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))
def _compare_eq_set(left, right):
def _compare_eq_set(left, right, verbose=False):
explanation = []
diff_left = left - right
diff_right = right - left
@@ -194,12 +202,41 @@ def _compare_eq_set(left, right):
return explanation
def _notin_text(term, text):
def _compare_eq_dict(left, right, verbose=False):
explanation = []
common = set(left).intersection(set(right))
same = dict((k, left[k]) for k in common if left[k] == right[k])
if same and not verbose:
explanation += ['Omitting %s identical items, use -v to show' %
len(same)]
elif same:
explanation += ['Common items:']
explanation += py.std.pprint.pformat(same).splitlines()
diff = set(k for k in common if left[k] != right[k])
if diff:
explanation += ['Differing items:']
for k in diff:
explanation += [py.io.saferepr({k: left[k]}) + ' != ' +
py.io.saferepr({k: right[k]})]
extra_left = set(left) - set(right)
if extra_left:
explanation.append('Left contains more items:')
explanation.extend(py.std.pprint.pformat(
dict((k, left[k]) for k in extra_left)).splitlines())
extra_right = set(right) - set(left)
if extra_right:
explanation.append('Right contains more items:')
explanation.extend(py.std.pprint.pformat(
dict((k, right[k]) for k in extra_right)).splitlines())
return explanation
def _notin_text(term, text, verbose=False):
index = text.find(term)
head = text[:index]
tail = text[index+len(term):]
correct_text = head + tail
diff = _diff_text(correct_text, text)
diff = _diff_text(correct_text, text, verbose)
newdiff = ['%s is contained here:' % py.io.saferepr(term, maxsize=42)]
for line in diff:
if line.startswith('Skipping'):

View File

@@ -1,27 +1,51 @@
""" per-test stdout/stderr capturing mechanisms, ``capsys`` and ``capfd`` function arguments. """
import pytest, py
import sys
import os
def pytest_addoption(parser):
group = parser.getgroup("general")
group._addoption('--capture', action="store", default=None,
metavar="method", type="choice", choices=['fd', 'sys', 'no'],
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="shortcut for --capture=no.")
@pytest.mark.tryfirst
def pytest_cmdline_parse(pluginmanager, args):
# we want to perform capturing already for plugin/conftest loading
if '-s' in args or "--capture=no" in args:
method = "no"
elif hasattr(os, 'dup') and '--capture=sys' not in args:
def pytest_load_initial_conftests(early_config, parser, args, __multicall__):
ns = parser.parse_known_args(args)
method = ns.capture
if not method:
method = "fd"
else:
if method == "fd" and not hasattr(os, "dup"):
method = "sys"
capman = CaptureManager(method)
pluginmanager.register(capman, "capturemanager")
early_config.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)
# 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)
# finally trigger conftest loading but while capturing (issue93)
capman.resumecapture()
try:
try:
return __multicall__.execute()
finally:
out, err = capman.suspendcapture()
except:
sys.stdout.write(out)
sys.stderr.write(err)
raise
def addouterr(rep, outerr):
for secname, content in zip(["out", "err"], outerr):
@@ -119,22 +143,20 @@ class CaptureManager:
return "", ""
def activate_funcargs(self, pyfuncitem):
if not hasattr(pyfuncitem, 'funcargs'):
return
assert not hasattr(self, '_capturing_funcargs')
self._capturing_funcargs = capturing_funcargs = []
for name, capfuncarg in pyfuncitem.funcargs.items():
if name in ('capsys', 'capfd'):
capturing_funcargs.append(capfuncarg)
capfuncarg._start()
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()
def deactivate_funcargs(self):
capturing_funcargs = getattr(self, '_capturing_funcargs', None)
if capturing_funcargs is not None:
while capturing_funcargs:
capfuncarg = capturing_funcargs.pop()
capfuncarg._finalize()
del self._capturing_funcargs
capturing_funcarg = getattr(self, '_capturing_funcarg', None)
if capturing_funcarg:
outerr = capturing_funcarg._finalize()
del self._capturing_funcarg
return outerr
def pytest_make_collect_report(self, __multicall__, collector):
method = self._getmethod(collector.config, collector.fspath)
@@ -169,33 +191,41 @@ class CaptureManager:
@pytest.mark.tryfirst
def pytest_runtest_makereport(self, __multicall__, item, call):
self.deactivate_funcargs()
funcarg_outerr = self.deactivate_funcargs()
rep = __multicall__.execute()
outerr = self.suspendcapture(item)
if not rep.passed:
addouterr(rep, outerr)
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
error_capsysfderror = "cannot use capsys and capfd at the same time"
def pytest_funcarg__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.
"""
return CaptureFuncarg(py.io.StdCapture)
if "capfd" in request._funcargs:
raise request.raiseerror(error_capsysfderror)
return CaptureFixture(py.io.StdCapture)
def pytest_funcarg__capfd(request):
"""enables capturing of writes to file descriptors 1 and 2 and makes
captured output available via ``capsys.readouterr()`` method calls
which return a ``(out, err)`` tuple.
"""
if "capsys" in request._funcargs:
request.raiseerror(error_capsysfderror)
if not hasattr(os, 'dup'):
py.test.skip("capfd funcarg needs os.dup")
return CaptureFuncarg(py.io.StdCaptureFD)
pytest.skip("capfd funcarg needs os.dup")
return CaptureFixture(py.io.StdCaptureFD)
class CaptureFuncarg:
class CaptureFixture:
def __init__(self, captureclass):
self.capture = captureclass(now=False)
@@ -204,11 +234,15 @@ class CaptureFuncarg:
def _finalize(self):
if hasattr(self, 'capture'):
self.capture.reset()
outerr = self._outerr = self.capture.reset()
del self.capture
return outerr
def readouterr(self):
return self.capture.readouterr()
try:
return self.capture.readouterr()
except AttributeError:
return self._outerr
def close(self):
self._finalize()

View File

@@ -2,24 +2,90 @@
import py
import sys, os
from _pytest import hookspec # the extension point definitions
from _pytest.core import PluginManager
import pytest
def pytest_cmdline_parse(pluginmanager, args):
config = Config(pluginmanager)
config.parse(args)
return config
# pytest startup
def main(args=None, plugins=None):
""" return exit code, after performing an in-process test run.
:arg args: list of command line arguments.
:arg plugins: list of plugin objects to be auto-registered during
initialization.
"""
config = _prepareconfig(args, plugins)
exitstatus = config.hook.pytest_cmdline_main(config=config)
return exitstatus
class cmdline: # compatibility namespace
main = staticmethod(main)
class UsageError(Exception):
""" error in py.test usage or invocation"""
_preinit = []
default_plugins = (
"mark main terminal runner python pdb unittest capture skipping "
"tmpdir monkeypatch recwarn pastebin helpconfig nose assertion genscript "
"junitxml resultlog doctest").split()
def _preloadplugins():
assert not _preinit
_preinit.append(get_plugin_manager())
def get_plugin_manager():
if _preinit:
return _preinit.pop(0)
# subsequent calls to main will create a fresh instance
pluginmanager = PytestPluginManager()
pluginmanager.config = config = Config(pluginmanager) # XXX attr needed?
for spec in default_plugins:
pluginmanager.import_plugin(spec)
return pluginmanager
def _prepareconfig(args=None, plugins=None):
if args is None:
args = sys.argv[1:]
elif isinstance(args, py.path.local):
args = [str(args)]
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)
pluginmanager = get_plugin_manager()
if plugins:
for plugin in plugins:
pluginmanager.register(plugin)
return pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args)
class PytestPluginManager(PluginManager):
def __init__(self, hookspecs=[hookspec]):
super(PytestPluginManager, self).__init__(hookspecs=hookspecs)
self.register(self)
if os.environ.get('PYTEST_DEBUG'):
err = sys.stderr
encoding = getattr(err, 'encoding', 'utf8')
try:
err = py.io.dupfile(err, encoding=encoding)
except Exception:
pass
self.trace.root.setwriter(err.write)
def pytest_configure(self, config):
config.addinivalue_line("markers",
"tryfirst: mark a hook implementation function such that the "
"plugin machinery will try to call it first/as early as possible.")
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.")
def pytest_unconfigure(config):
while 1:
try:
fin = config._cleanup.pop()
except IndexError:
break
fin()
class Parser:
""" Parser for command line arguments. """
""" Parser for command line arguments and ini-file values. """
def __init__(self, usage=None, processopt=None):
self._anonymous = OptionGroup("custom options", parser=self)
@@ -35,15 +101,17 @@ class Parser:
if option.dest:
self._processopt(option)
def addnote(self, note):
self._notes.append(note)
def getgroup(self, name, description="", after=None):
""" get (or create) a named option Group.
:name: unique name of the option group.
:name: name of the option group.
:description: long description for --help output.
:after: name of other group, used for ordering --help output.
The returned group object has an ``addoption`` method with the same
signature as :py:func:`parser.addoption
<_pytest.config.Parser.addoption>` but will be shown in the
respective group in the output of ``pytest. --help``.
"""
for group in self._groups:
if group.name == name:
@@ -57,33 +125,222 @@ class Parser:
return group
def addoption(self, *opts, **attrs):
""" add an optparse-style option. """
""" register a command line option.
:opts: option names, can be short or long options.
:attrs: same attributes which the ``add_option()`` function of the
`optparse library
<http://docs.python.org/library/optparse.html#module-optparse>`_
accepts.
After command line parsing options are available on the pytest config
object via ``config.option.NAME`` where ``NAME`` is usually set
by passing a ``dest`` attribute, for example
``addoption("--long", dest="NAME", ...)``.
"""
self._anonymous.addoption(*opts, **attrs)
def parse(self, args):
self.optparser = optparser = MyOptionParser(self)
from _pytest._argcomplete import try_argcomplete
self.optparser = self._getparser()
try_argcomplete(self.optparser)
return self.optparser.parse_args([str(x) for x in args])
def _getparser(self):
from _pytest._argcomplete import filescompleter
optparser = MyOptionParser(self)
groups = self._groups + [self._anonymous]
for group in groups:
if group.options:
desc = group.description or group.name
optgroup = py.std.optparse.OptionGroup(optparser, desc)
optgroup.add_options(group.options)
optparser.add_option_group(optgroup)
return self.optparser.parse_args([str(x) for x in args])
arggroup = optparser.add_argument_group(desc)
for option in group.options:
n = option.names()
a = option.attrs()
arggroup.add_argument(*n, **a)
# bash like autocompletion for dirs (appending '/')
optparser.add_argument(FILE_OR_DIR, nargs='*'
).completer=filescompleter
return optparser
def parse_setoption(self, args, option):
parsedoption, args = self.parse(args)
parsedoption = self.parse(args)
for name, value in parsedoption.__dict__.items():
setattr(option, name, value)
return args
return getattr(parsedoption, FILE_OR_DIR)
def parse_known_args(self, args):
optparser = self._getparser()
args = [str(x) for x in args]
return optparser.parse_known_args(args)[0]
def addini(self, name, help, type=None, default=None):
""" add an ini-file option with the given name and description. """
""" register an ini-file option.
:name: name of the ini-variable
:type: type of the variable, can be ``pathlist``, ``args`` or ``linelist``.
:default: default value if no ini-file option exists but is queried.
The value of ini-variables can be retrieved via a call to
:py:func:`config.getini(name) <_pytest.config.Config.getini>`.
"""
assert type in (None, "pathlist", "args", "linelist")
self._inidict[name] = (help, type, default)
self._ininames.append(name)
class ArgumentError(Exception):
"""
Raised if an Argument instance is created with invalid or
inconsistent arguments.
"""
def __init__(self, msg, option):
self.msg = msg
self.option_id = str(option)
def __str__(self):
if self.option_id:
return "option %s: %s" % (self.option_id, self.msg)
else:
return self.msg
class Argument:
"""class that mimics the necessary behaviour of py.std.optparse.Option """
_typ_map = {
'int': int,
'string': str,
}
# enable after some grace period for plugin writers
TYPE_WARN = False
def __init__(self, *names, **attrs):
"""store parms in private vars for use in add_argument"""
self._attrs = attrs
self._short_opts = []
self._long_opts = []
self.dest = attrs.get('dest')
if self.TYPE_WARN:
try:
help = attrs['help']
if '%default' in help:
py.std.warnings.warn(
'py.test now uses argparse. "%default" should be'
' changed to "%(default)s" ',
FutureWarning,
stacklevel=3)
except KeyError:
pass
try:
typ = attrs['type']
except KeyError:
pass
else:
# this might raise a keyerror as well, don't want to catch that
if isinstance(typ, py.builtin._basestring):
if typ == 'choice':
if self.TYPE_WARN:
py.std.warnings.warn(
'type argument to addoption() is a string %r.'
' For parsearg this is optional and when supplied '
' should be a type.'
' (options: %s)' % (typ, names),
FutureWarning,
stacklevel=3)
# argparse expects a type here take it from
# the type of the first element
attrs['type'] = type(attrs['choices'][0])
else:
if self.TYPE_WARN:
py.std.warnings.warn(
'type argument to addoption() is a string %r.'
' For parsearg this should be a type.'
' (options: %s)' % (typ, names),
FutureWarning,
stacklevel=3)
attrs['type'] = Argument._typ_map[typ]
# used in test_parseopt -> test_parse_defaultgetter
self.type = attrs['type']
else:
self.type = typ
try:
# attribute existence is tested in Config._processopt
self.default = attrs['default']
except KeyError:
pass
self._set_opt_strings(names)
if not self.dest:
if self._long_opts:
self.dest = self._long_opts[0][2:].replace('-', '_')
else:
try:
self.dest = self._short_opts[0][1:]
except IndexError:
raise ArgumentError(
'need a long or short option', self)
def names(self):
return self._short_opts + self._long_opts
def attrs(self):
# update any attributes set by processopt
attrs = 'default dest help'.split()
if self.dest:
attrs.append(self.dest)
for attr in attrs:
try:
self._attrs[attr] = getattr(self, attr)
except AttributeError:
pass
if self._attrs.get('help'):
a = self._attrs['help']
a = a.replace('%default', '%(default)s')
#a = a.replace('%prog', '%(prog)s')
self._attrs['help'] = a
return self._attrs
def _set_opt_strings(self, opts):
"""directly from optparse
might not be necessary as this is passed to argparse later on"""
for opt in opts:
if len(opt) < 2:
raise ArgumentError(
"invalid option string %r: "
"must be at least two characters long" % opt, self)
elif len(opt) == 2:
if not (opt[0] == "-" and opt[1] != "-"):
raise ArgumentError(
"invalid short option string %r: "
"must be of the form -x, (x any non-dash char)" % opt,
self)
self._short_opts.append(opt)
else:
if not (opt[0:2] == "--" and opt[2] != "-"):
raise ArgumentError(
"invalid long option string %r: "
"must start with --, followed by non-dash" % opt,
self)
self._long_opts.append(opt)
def __repr__(self):
retval = 'Argument('
if self._short_opts:
retval += '_short_opts: ' + repr(self._short_opts) + ', '
if self._long_opts:
retval += '_long_opts: ' + repr(self._long_opts) + ', '
retval += 'dest: ' + repr(self.dest) + ', '
if hasattr(self, 'type'):
retval += 'type: ' + repr(self.type) + ', '
if hasattr(self, 'default'):
retval += 'default: ' + repr(self.default) + ', '
if retval[-2:] == ', ': # always long enough to test ("Argument(" )
retval = retval[:-2]
retval += ')'
return retval
class OptionGroup:
def __init__(self, name, description="", parser=None):
self.name = name
@@ -92,12 +349,18 @@ class OptionGroup:
self.parser = parser
def addoption(self, *optnames, **attrs):
""" add an option to this group. """
option = py.std.optparse.Option(*optnames, **attrs)
""" add an option to this group.
if a shortened version of a long option is specified it will
be suppressed in the help. addoption('--twowords', '--two-words')
results in help showing '--two-words' only, but --twowords gets
accepted **and** the automatic destination is in args.twowords
"""
option = Argument(*optnames, **attrs)
self._addoption_instance(option, shortupper=False)
def _addoption(self, *optnames, **attrs):
option = py.std.optparse.Option(*optnames, **attrs)
option = Argument(*optnames, **attrs)
self._addoption_instance(option, shortupper=True)
def _addoption_instance(self, option, shortupper=False):
@@ -110,11 +373,12 @@ class OptionGroup:
self.options.append(option)
class MyOptionParser(py.std.optparse.OptionParser):
class MyOptionParser(py.std.argparse.ArgumentParser):
def __init__(self, parser):
self._parser = parser
py.std.optparse.OptionParser.__init__(self, usage=parser._usage,
add_help_option=False)
py.std.argparse.ArgumentParser.__init__(self, usage=parser._usage,
add_help=False, formatter_class=DropShorterLongHelpFormatter)
def format_epilog(self, formatter):
hints = self._parser.hints
if hints:
@@ -123,6 +387,66 @@ class MyOptionParser(py.std.optparse.OptionParser):
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')
self.error(msg % ' '.join(argv))
getattr(args, FILE_OR_DIR).extend(argv)
return args
class DropShorterLongHelpFormatter(py.std.argparse.HelpFormatter):
"""shorten help for long options that differ only in extra hyphens
- collapse **long** options that are the same except for extra hyphens
- special action attribute map_long_option allows surpressing additional
long options
- shortcut if there are only two options and one of them is a short one
- 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)
if orgstr and orgstr[0] != '-': # only optional arguments
return orgstr
res = getattr(action, '_formatted_action_invocation', None)
if res:
return res
options = orgstr.split(', ')
if len(options) == 2 and (len(options[0]) == 2 or len(options[1]) == 2):
# a shortcut for '-h, --help' or '--abc', '-a'
action._formatted_action_invocation = orgstr
return orgstr
return_list = []
option_map = getattr(action, 'map_long_option', {})
if option_map is None:
option_map = {}
short_long = {}
for option in options:
if len(option) == 2 or option[2] == ' ':
continue
if not option.startswith('--'):
raise ArgumentError('long optional argument without "--": [%s]'
% (option), self)
xxoption = option[2:]
if xxoption.split()[0] not in option_map:
shortened = xxoption.replace('-', '')
if shortened not in short_long or \
len(short_long[shortened]) < len(xxoption):
short_long[shortened] = xxoption
# now short_long has been filled out to the longest with dashes
# **and** we keep the right option ordering from add_argument
for option in options: #
if len(option) == 2 or option[2] == ' ':
return_list.append(option)
if option[2:] == short_long.get(option.replace('-', '')):
return_list.append(option)
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.
@@ -154,43 +478,40 @@ class Conftest(object):
p = current.join(opt1[len(opt)+1:], abs=1)
self._confcutdir = p
break
for arg in args + [current]:
foundanchor = False
for arg in args:
if hasattr(arg, 'startswith') and arg.startswith("--"):
continue
anchor = current.join(arg, abs=1)
if anchor.check(): # we found some file object
self._path2confmods[None] = self.getconftestmodules(anchor)
# let's also consider test* dirs
if anchor.check(dir=1):
for x in anchor.listdir("test*"):
if x.check(dir=1):
self.getconftestmodules(x)
break
else:
assert 0, "no root of filesystem?"
if exists(anchor): # we found some file object
self._try_load_conftest(anchor)
foundanchor = True
if not foundanchor:
self._try_load_conftest(current)
def _try_load_conftest(self, anchor):
self._path2confmods[None] = self.getconftestmodules(anchor)
# let's also consider test* subdirs
if anchor.check(dir=1):
for x in anchor.listdir("test*"):
if x.check(dir=1):
self.getconftestmodules(x)
def getconftestmodules(self, path):
""" return a list of imported conftest modules for the given path. """
try:
clist = self._path2confmods[path]
except KeyError:
if path is None:
raise ValueError("missing default confest.")
dp = path.dirpath()
raise ValueError("missing default conftest.")
clist = []
if dp != path:
cutdir = self._confcutdir
if cutdir and path != cutdir and not path.relto(cutdir):
pass
else:
conftestpath = path.join("conftest.py")
if conftestpath.check(file=1):
clist.append(self.importconftest(conftestpath))
clist[:0] = self.getconftestmodules(dp)
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))
self._path2confmods[path] = clist
# be defensive: avoid changes from caller side to
# affect us by always returning a copy of the actual list
return clist[:]
return clist
def rget(self, name, path=None):
mod, value = self.rget_with_confmod(name, path)
@@ -242,31 +563,88 @@ class CmdOptions(object):
def __repr__(self):
return "<CmdOptions %r>" %(self.__dict__,)
FILE_OR_DIR = 'file_or_dir'
class Config(object):
""" access to configuration values, pluginmanager and plugin hooks. """
def __init__(self, pluginmanager=None):
#: command line option values, usually added via parser.addoption(...)
#: or parser.getgroup(...).addoption(...) calls
def __init__(self, pluginmanager):
#: access to command line option as attributes.
#: (deprecated), use :py:func:`getoption() <_pytest.config.Config.getoption>` instead
self.option = CmdOptions()
_a = FILE_OR_DIR
self._parser = Parser(
usage="usage: %prog [options] [file_or_dir] [file_or_dir] [...]",
usage="%%(prog)s [options] [%s] [%s] [...]" % (_a, _a),
processopt=self._processopt,
)
#: a pluginmanager instance
self.pluginmanager = pluginmanager or PluginManager(load=True)
self.pluginmanager = pluginmanager
self.trace = self.pluginmanager.trace.root.get("config")
self._conftest = Conftest(onimport=self._onimportconftest)
self.hook = self.pluginmanager.hook
self._inicache = {}
self._opt2dest = {}
self._cleanup = []
self.pluginmanager.register(self, "pytestconfig")
self.pluginmanager.set_register_callback(self._register_plugin)
self._configured = False
def _register_plugin(self, plugin, name):
call_plugin = self.pluginmanager.call_plugin
call_plugin(plugin, "pytest_addhooks",
{'pluginmanager': self.pluginmanager})
self.hook.pytest_plugin_registered(plugin=plugin,
manager=self.pluginmanager)
dic = call_plugin(plugin, "pytest_namespace", {}) or {}
if dic:
import pytest
setns(pytest, dic)
call_plugin(plugin, "pytest_addoption", {'parser': self._parser})
if self._configured:
call_plugin(plugin, "pytest_configure", {'config': self})
def do_configure(self):
assert not self._configured
self._configured = True
self.hook.pytest_configure(config=self)
def do_unconfigure(self):
assert self._configured
self._configured = False
self.hook.pytest_unconfigure(config=self)
self.pluginmanager.ensure_shutdown()
def pytest_cmdline_parse(self, pluginmanager, args):
assert self == pluginmanager.config, (self, pluginmanager.config)
self.parse(args)
return self
def pytest_unconfigure(config):
while config._cleanup:
fin = config._cleanup.pop()
fin()
def notify_exception(self, excinfo, option=None):
if option and option.fulltrace:
style = "long"
else:
style = "native"
excrepr = excinfo.getrepr(funcargs=True,
showlocals=getattr(option, 'showlocals', False),
style=style,
)
res = self.hook.pytest_internalerror(excrepr=excrepr,
excinfo=excinfo)
if not py.builtin.any(res):
for line in str(excrepr).split("\n"):
sys.stderr.write("INTERNALERROR> %s\n" %line)
sys.stderr.flush()
@classmethod
def fromdictargs(cls, option_dict, args):
""" constructor useable for subprocesses. """
config = cls()
# XXX slightly crude way to initialize capturing
import _pytest.capture
_pytest.capture.pytest_cmdline_parse(config.pluginmanager, args)
pluginmanager = get_plugin_manager()
config = pluginmanager.config
config._preparse(args, addopts=False)
config.option.__dict__.update(option_dict)
for x in config.option.plugins:
@@ -278,6 +656,9 @@ class Config(object):
self.pluginmanager.consider_conftest(conftestmodule)
def _processopt(self, opt):
for name in opt._short_opts + opt._long_opts:
self._opt2dest[name] = opt.dest
if hasattr(opt, 'default') and opt.dest:
if not hasattr(self.option, opt.dest):
setattr(self.option, opt.dest, opt.default)
@@ -289,21 +670,9 @@ class Config(object):
plugins += self._conftest.getconftestmodules(fspath)
return plugins
def _setinitialconftest(self, args):
# capture output during conftest init (#issue93)
# XXX introduce load_conftest hook to avoid needing to know
# about capturing plugin here
capman = self.pluginmanager.getplugin("capturemanager")
capman.resumecapture()
try:
try:
self._conftest.setinitial(args)
finally:
out, err = capman.suspendcapture() # logging might have got it
except:
sys.stdout.write(out)
sys.stderr.write(err)
raise
def pytest_load_initial_conftests(self, parser, args):
self._conftest.setinitial(args)
pytest_load_initial_conftests.trylast = True
def _initini(self, args):
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
@@ -318,12 +687,11 @@ class Config(object):
self.pluginmanager.consider_preparse(args)
self.pluginmanager.consider_setuptools_entrypoints()
self.pluginmanager.consider_env()
self._setinitialconftest(args)
self.pluginmanager.do_addoption(self._parser)
if addopts:
self.hook.pytest_cmdline_preparse(config=self, args=args)
self.hook.pytest_load_initial_conftests(early_config=self,
args=args, parser=self._parser)
def _checkversion(self):
import pytest
minver = self.inicfg.get('minversion', None)
if minver:
ver = minver.split(".")
@@ -341,6 +709,8 @@ class Config(object):
"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:
@@ -356,8 +726,9 @@ class Config(object):
x.append(line) # modifies the cached list inline
def getini(self, name):
""" return configuration value from an ini file. If the
specified name hasn't been registered through a prior ``parse.addini``
""" return configuration value from an :ref:`ini file <inifiles>`. If the
specified name hasn't been registered through a prior
:py:func:`parser.addini <pytest.config.Parser.addini>`
call (usually from a plugin), a ValueError is raised. """
try:
return self._inicache[name]
@@ -411,8 +782,22 @@ class Config(object):
self._checkconftest(name)
return self._conftest.rget(name, path)
def getoption(self, name):
""" 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.
"""
name = self._opt2dest.get(name, name)
try:
return getattr(self.option, name)
except AttributeError:
raise ValueError("no option named %r" % (name,))
def getvalue(self, name, path=None):
""" return ``name`` value looked set from command line options.
""" 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.
@@ -434,6 +819,11 @@ class Config(object):
except KeyError:
py.test.skip("no %r value found" %(name,))
def exists(path, ignore=EnvironmentError):
try:
return path.check()
except ignore:
return False
def getcfg(args, inibasenames):
args = [x for x in args if not str(x).startswith("-")]
@@ -444,20 +834,29 @@ def getcfg(args, inibasenames):
for base in arg.parts(reverse=True):
for inibasename in inibasenames:
p = base.join(inibasename)
if p.check():
if exists(p):
iniconfig = py.iniconfig.IniConfig(p)
if 'pytest' in iniconfig.sections:
return iniconfig['pytest']
return {}
def findupwards(current, basename):
current = py.path.local(current)
while 1:
p = current.join(basename)
if p.check():
return p
p = current.dirpath()
if p == current:
return
current = p
def setns(obj, dic):
import pytest
for name, value in dic.items():
if isinstance(value, dict):
mod = getattr(obj, name, None)
if mod is None:
modname = "pytest.%s" % name
mod = py.std.types.ModuleType(modname)
sys.modules[modname] = mod
mod.__all__ = []
setattr(obj, name, mod)
obj.__all__.append(name)
setns(mod, value)
else:
setattr(obj, name, value)
obj.__all__.append(name)
#if obj != pytest:
# pytest.__all__.append(name)
setattr(pytest, name, value)

View File

@@ -1,20 +1,13 @@
"""
pytest PluginManager, basic initialization and tracing.
(c) Holger Krekel 2004-2010
"""
import sys, os
import sys
import inspect
import py
from _pytest import hookspec # the extension point definitions
assert py.__version__.split(".")[:2] >= ['1', '4'], ("installation problem: "
"%s is too old, remove or upgrade 'py'" % (py.__version__))
default_plugins = (
"config mark main terminal runner python pdb unittest capture skipping "
"tmpdir monkeypatch recwarn pastebin helpconfig nose assertion genscript "
"junitxml resultlog doctest").split()
class TagTracer:
def __init__(self):
self._tag2proc = {}
@@ -24,12 +17,28 @@ class TagTracer:
def get(self, name):
return TagTracerSub(self, (name,))
def format_message(self, tags, args):
if isinstance(args[-1], dict):
extra = args[-1]
args = args[:-1]
else:
extra = {}
content = " ".join(map(str, args))
indent = " " * self.indent
lines = [
"%s%s [%s]\n" %(indent, content, ":".join(tags))
]
for name, value in extra.items():
lines.append("%s %s: %s\n" % (indent, name, value))
return lines
def processmessage(self, tags, args):
if self.writer is not None:
if args:
indent = " " * self.indent
content = " ".join(map(str, args))
self.writer("%s%s [%s]\n" %(indent, content, ":".join(tags)))
if self.writer is not None and args:
lines = self.format_message(tags, args)
self.writer(''.join(lines))
try:
self._tag2proc[tags](tags, args)
except KeyError:
@@ -57,36 +66,36 @@ class TagTracerSub:
return self.__class__(self.root, self.tags + (name,))
class PluginManager(object):
def __init__(self, load=False):
def __init__(self, hookspecs=None):
self._name2plugin = {}
self._listattrcache = {}
self._plugins = []
self._hints = []
self.trace = TagTracer().get("pluginmanage")
self._plugin_distinfo = []
if os.environ.get('PYTEST_DEBUG'):
err = sys.stderr
encoding = getattr(err, 'encoding', 'utf8')
try:
err = py.io.dupfile(err, encoding=encoding)
except Exception:
pass
self.trace.root.setwriter(err.write)
self.hook = HookRelay([hookspec], pm=self)
self.register(self)
if load:
for spec in default_plugins:
self.import_plugin(spec)
self._shutdown = []
self.hook = HookRelay(hookspecs or [], pm=self)
def do_configure(self, config):
# backward compatibility
config.do_configure()
def set_register_callback(self, callback):
assert not hasattr(self, "_registercallback")
self._registercallback = callback
def register(self, plugin, name=None, prepend=False):
assert not self.isregistered(plugin), plugin
if self._name2plugin.get(name, None) == -1:
return
name = name or getattr(plugin, '__name__', str(id(plugin)))
if name in self._name2plugin:
return False
if self.isregistered(plugin, name):
raise ValueError("Plugin already registered: %s=%s\n%s" %(
name, plugin, self._name2plugin))
#self.trace("registering", name, plugin)
self._name2plugin[name] = plugin
self.call_plugin(plugin, "pytest_addhooks", {'pluginmanager': self})
self.hook.pytest_plugin_registered(manager=self, plugin=plugin)
reg = getattr(self, "_registercallback", None)
if reg is not None:
reg(plugin, name)
if not prepend:
self._plugins.append(plugin)
else:
@@ -97,11 +106,21 @@ class PluginManager(object):
if plugin is None:
plugin = self.getplugin(name=name)
self._plugins.remove(plugin)
self.hook.pytest_plugin_unregistered(plugin=plugin)
for name, value in list(self._name2plugin.items()):
if value == plugin:
del self._name2plugin[name]
def add_shutdown(self, func):
self._shutdown.append(func)
def ensure_shutdown(self):
while self._shutdown:
func = self._shutdown.pop()
func()
self._plugins = []
self._name2plugin.clear()
self._listattrcache.clear()
def isregistered(self, plugin, name=None):
if self.getplugin(name) is not None:
return True
@@ -109,8 +128,8 @@ class PluginManager(object):
if plugin == val:
return True
def addhooks(self, spec):
self.hook._addhooks(spec, prefix="pytest_")
def addhooks(self, spec, prefix="pytest_"):
self.hook._addhooks(spec, prefix=prefix)
def getplugins(self):
return list(self._plugins)
@@ -192,7 +211,6 @@ class PluginManager(object):
if self.getplugin(modname) is not None:
return
try:
#self.trace("importing", modname)
mod = importplugin(modname)
except KeyboardInterrupt:
raise
@@ -211,82 +229,6 @@ class PluginManager(object):
self.register(mod, modname)
self.consider_module(mod)
def pytest_configure(self, config):
config.addinivalue_line("markers",
"tryfirst: mark a hook implementation function such that the "
"plugin machinery will try to call it first/as early as possible.")
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.")
def pytest_plugin_registered(self, plugin):
import pytest
dic = self.call_plugin(plugin, "pytest_namespace", {}) or {}
if dic:
self._setns(pytest, dic)
if hasattr(self, '_config'):
self.call_plugin(plugin, "pytest_addoption",
{'parser': self._config._parser})
self.call_plugin(plugin, "pytest_configure",
{'config': self._config})
def _setns(self, obj, dic):
import pytest
for name, value in dic.items():
if isinstance(value, dict):
mod = getattr(obj, name, None)
if mod is None:
modname = "pytest.%s" % name
mod = py.std.types.ModuleType(modname)
sys.modules[modname] = mod
mod.__all__ = []
setattr(obj, name, mod)
obj.__all__.append(name)
self._setns(mod, value)
else:
setattr(obj, name, value)
obj.__all__.append(name)
#if obj != pytest:
# pytest.__all__.append(name)
setattr(pytest, name, value)
def pytest_terminal_summary(self, terminalreporter):
tw = terminalreporter._tw
if terminalreporter.config.option.traceconfig:
for hint in self._hints:
tw.line("hint: %s" % hint)
def do_addoption(self, parser):
mname = "pytest_addoption"
methods = reversed(self.listattr(mname))
MultiCall(methods, {'parser': parser}).execute()
def do_configure(self, config):
assert not hasattr(self, '_config')
self._config = config
config.hook.pytest_configure(config=self._config)
def do_unconfigure(self, config):
config = self._config
del self._config
config.hook.pytest_unconfigure(config=config)
config.pluginmanager.unregister(self)
def notify_exception(self, excinfo, option=None):
if option and option.fulltrace:
style = "long"
else:
style = "native"
excrepr = excinfo.getrepr(funcargs=True,
showlocals=getattr(option, 'showlocals', False),
style=style,
)
res = self.hook.pytest_internalerror(excrepr=excrepr)
if not py.builtin.any(res):
for line in str(excrepr).split("\n"):
sys.stderr.write("INTERNALERROR> %s\n" %line)
sys.stderr.flush()
def listattr(self, attrname, plugins=None):
if plugins is None:
plugins = self._plugins
@@ -321,13 +263,20 @@ def importplugin(importspec):
name = importspec
try:
mod = "_pytest." + name
return __import__(mod, None, None, '__doc__')
#print >>sys.stderr, "tryimport", mod
__import__(mod)
return sys.modules[mod]
except ImportError:
#e = py.std.sys.exc_info()[1]
#if str(e).find(name) == -1:
# raise
pass #
return __import__(importspec, None, None, '__doc__')
try:
#print >>sys.stderr, "tryimport", importspec
__import__(importspec)
except ImportError:
raise ImportError(importspec)
return sys.modules[importspec]
class MultiCall:
""" execute a call into multiple python functions/methods. """
@@ -434,44 +383,3 @@ class HookCaller:
self.trace.root.indent -= 1
return res
_preinit = []
def _preloadplugins():
_preinit.append(PluginManager(load=True))
def _prepareconfig(args=None, plugins=None):
if args is None:
args = sys.argv[1:]
elif isinstance(args, py.path.local):
args = [str(args)]
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)
if _preinit:
_pluginmanager = _preinit.pop(0)
else: # subsequent calls to main will create a fresh instance
_pluginmanager = PluginManager(load=True)
hook = _pluginmanager.hook
if plugins:
for plugin in plugins:
_pluginmanager.register(plugin)
return hook.pytest_cmdline_parse(
pluginmanager=_pluginmanager, args=args)
def main(args=None, plugins=None):
""" returned exit code integer, after an in-process testing run
with the given command line arguments, preloading an optional list
of passed in plugin objects. """
try:
config = _prepareconfig(args, plugins)
exitstatus = config.hook.pytest_cmdline_main(config=config)
except UsageError:
e = sys.exc_info()[1]
sys.stderr.write("ERROR: %s\n" %(e.args[0],))
exitstatus = 3
return exitstatus
class UsageError(Exception):
""" error in py.test usage or invocation"""

View File

@@ -1,6 +1,7 @@
""" discover and run doctests in modules and test files."""
import pytest, py
from _pytest.python import FixtureRequest, FuncFixtureInfo
from py._code.code import TerminalRepr, ReprFileLocation
def pytest_addoption(parser):
@@ -33,6 +34,14 @@ class ReprFailDoctest(TerminalRepr):
self.reprlocation.toterminal(tw)
class DoctestItem(pytest.Item):
def __init__(self, name, parent, runner=None, dtest=None):
super(DoctestItem, self).__init__(name, parent)
self.runner = runner
self.dtest = dtest
def runtest(self):
self.runner.run(self.dtest)
def repr_failure(self, excinfo):
doctest = py.std.doctest
if excinfo.errisinstance((doctest.DocTestFailure,
@@ -41,17 +50,27 @@ class DoctestItem(pytest.Item):
example = doctestfailure.example
test = doctestfailure.test
filename = test.filename
lineno = test.lineno + example.lineno + 1
if test.lineno is None:
lineno = None
else:
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
filelines = py.path.local(filename).readlines(cr=0)
i = max(test.lineno, max(0, lineno - 10)) # XXX?
lines = []
for line in filelines[i:lineno]:
lines.append("%03d %s" % (i+1, line))
i += 1
if lineno is not None:
i = max(test.lineno, max(0, lineno - 10)) # XXX?
for line in filelines[i:lineno]:
lines.append("%03d %s" % (i+1, line))
i += 1
else:
lines.append('EXAMPLE LOCATION UNKNOWN, not showing all tests of that example')
indent = '>>>'
for line in example.source.splitlines():
lines.append('??? %s %s' % (indent, line))
indent = '...'
if excinfo.errisinstance(doctest.DocTestFailure):
lines += checker.output_difference(example,
doctestfailure.got, REPORT_UDIFF).split("\n")
@@ -65,23 +84,37 @@ class DoctestItem(pytest.Item):
return super(DoctestItem, self).repr_failure(excinfo)
def reportinfo(self):
return self.fspath, None, "[doctest]"
return self.fspath, None, "[doctest] %s" % self.name
class DoctestTextfile(DoctestItem, pytest.File):
def runtest(self):
doctest = py.std.doctest
# satisfy `FixtureRequest` constructor...
self.funcargs = {}
self._fixtureinfo = FuncFixtureInfo((), [], {})
fixture_request = FixtureRequest(self)
failed, tot = doctest.testfile(
str(self.fspath), module_relative=False,
optionflags=doctest.ELLIPSIS,
extraglobs=dict(getfixture=fixture_request.getfuncargvalue),
raise_on_error=True, verbose=0)
class DoctestModule(DoctestItem, pytest.File):
def runtest(self):
class DoctestModule(pytest.File):
def collect(self):
doctest = py.std.doctest
if self.fspath.basename == "conftest.py":
module = self.config._conftest.importconftest(self.fspath)
else:
module = self.fspath.pyimport()
failed, tot = doctest.testmod(
module, raise_on_error=True, verbose=0,
optionflags=doctest.ELLIPSIS)
# satisfy `FixtureRequest` constructor...
self.funcargs = {}
self._fixtureinfo = FuncFixtureInfo((), [], {})
fixture_request = FixtureRequest(self)
doctest_globals = dict(getfixture=fixture_request.getfuncargvalue)
# uses internal doctest module parsing mechanism
finder = doctest.DocTestFinder()
runner = doctest.DebugRunner(verbose=0, optionflags=doctest.ELLIPSIS)
for test in finder.find(module, module.__name__,
extraglobs=doctest_globals):
if test.examples: # skip empty doctests
yield DoctestItem(test.name, self, runner, test)

View File

@@ -1,5 +1,6 @@
""" generate a single-file self-contained version of py.test """
import py
import sys
def find_toplevel(name):
for syspath in py.std.sys.path:
@@ -59,11 +60,21 @@ def pytest_addoption(parser):
def pytest_cmdline_main(config):
genscript = config.getvalue("genscript")
if genscript:
tw = py.io.TerminalWriter()
deps = ['py', '_pytest', 'pytest']
if sys.version_info < (2,7):
deps.append("argparse")
tw.line("generated script will run on python2.5-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)
script = generate_script(
'import py; raise SystemExit(py.test.cmdline.main())',
['py', '_pytest', 'pytest'],
deps,
)
genscript = py.path.local(genscript)
genscript.write(script)
tw.line("generated pytest standalone script: %s" % genscript,
bold=True)
return 0

View File

@@ -13,8 +13,8 @@ def pytest_addoption(parser):
group._addoption('-p', action="append", dest="plugins", default = [],
metavar="name",
help="early-load given plugin (multi-allowed).")
group.addoption('--traceconfig',
action="store_true", dest="traceconfig", default=False,
group.addoption('--traceconfig', '--trace-config',
action="store_true", default=False,
help="trace considerations of conftest.py files."),
group.addoption('--debug',
action="store_true", dest="debug", default=False,
@@ -54,14 +54,15 @@ def pytest_cmdline_main(config):
sys.stderr.write(line + "\n")
return 0
elif config.option.help:
config.pluginmanager.do_configure(config)
config.do_configure()
showhelp(config)
config.pluginmanager.do_unconfigure(config)
config.do_unconfigure()
return 0
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")
@@ -79,6 +80,8 @@ def showhelp(config):
tw.line() ; tw.line()
#tw.sep("=")
tw.line("to see available markers type: py.test --markers")
tw.line("to see available fixtures type: py.test --fixtures")
return
tw.line("conftest.py options:")

View File

@@ -20,11 +20,31 @@ def pytest_cmdline_parse(pluginmanager, args):
pytest_cmdline_parse.firstresult = True
def pytest_cmdline_preparse(config, args):
"""modify command line arguments before option parsing. """
"""(deprecated) modify command line arguments before option parsing. """
def pytest_addoption(parser):
"""add optparse-style options and ini-style config values via calls
to ``parser.addoption`` and ``parser.addini(...)``.
"""register argparse-style options and ini-style config values.
This function must be implemented in a :ref:`plugin <pluginorder>` and is
called once at the beginning of a test run.
:arg parser: To add command line options, call
:py:func:`parser.addoption(...) <_pytest.config.Parser.addoption>`.
To add ini-file values call :py:func:`parser.addini(...)
<_pytest.config.Parser.addini>`.
Options can later be accessed through the
:py:class:`config <_pytest.config.Config>` object, respectively:
- :py:func:`config.getoption(name) <_pytest.config.Config.getoption>` to
retrieve the value of a command line option.
- :py:func:`config.getini(name) <_pytest.config.Config.getini>` to retrieve
a value read from an ini-style file.
The config object is passed around on many internal objects via the ``.config``
attribute or can be retrieved as the ``pytestconfig`` fixture or accessed
via (deprecated) ``pytest.config``.
"""
def pytest_cmdline_main(config):
@@ -32,8 +52,12 @@ def pytest_cmdline_main(config):
implementation will invoke the configure hooks and runtest_mainloop. """
pytest_cmdline_main.firstresult = True
def pytest_load_initial_conftests(args, early_config, parser):
""" implements loading initial conftests.
"""
def pytest_configure(config):
""" called after command line options have been parsed.
""" called after command line options have been parsed
and all plugins and initial conftest files been loaded.
"""
@@ -193,7 +217,7 @@ def pytest_assertrepr_compare(config, op, left, right):
# hooks for influencing reporting (invoked from _pytest_terminal)
# -------------------------------------------------------------------------
def pytest_report_header(config):
def pytest_report_header(config, startdir):
""" return a string to be displayed as header info for terminal reporting."""
def pytest_report_teststatus(report):
@@ -201,7 +225,7 @@ def pytest_report_teststatus(report):
pytest_report_teststatus.firstresult = True
def pytest_terminal_summary(terminalreporter):
""" add additional section in terminal summary reporting. """
""" add additional section in terminal summary reporting. """
# -------------------------------------------------------------------------
# doctest hooks
@@ -216,13 +240,20 @@ pytest_doctest_prepare_content.firstresult = True
# -------------------------------------------------------------------------
def pytest_plugin_registered(plugin, manager):
""" a new py lib plugin got registered. """
""" a new pytest plugin got registered. """
def pytest_plugin_unregistered(plugin):
""" a py lib plugin got unregistered. """
def pytest_internalerror(excrepr):
def pytest_internalerror(excrepr, excinfo):
""" called for internal errors. """
def pytest_keyboard_interrupt(excinfo):
""" called for keyboard interrupt. """
def pytest_exception_interact(node, call, report):
""" (experimental, new in 2.4) called when
an exception was raised which can potentially be
interactively handled.
This hook is only called if an exception was raised
that is not an internal exception like "skip.Exception".
"""

254
_pytest/impl Normal file
View File

@@ -0,0 +1,254 @@
Sorting per-resource
-----------------------------
for any given set of items:
- collect items per session-scoped parametrized funcarg
- re-order until items no parametrizations are mixed
examples:
test()
test1(s1)
test1(s2)
test2()
test3(s1)
test3(s2)
gets sorted to:
test()
test2()
test1(s1)
test3(s1)
test1(s2)
test3(s2)
the new @setup functions
--------------------------------------
Consider a given @setup-marked function::
@pytest.mark.setup(maxscope=SCOPE)
def mysetup(request, arg1, arg2, ...)
...
request.addfinalizer(fin)
...
then FUNCARGSET denotes the set of (arg1, arg2, ...) funcargs and
all of its dependent funcargs. The mysetup function will execute
for any matching test item once per scope.
The scope is determined as the minimum scope of all scopes of the args
in FUNCARGSET and the given "maxscope".
If mysetup has been called and no finalizers have been called it is
called "active".
Furthermore the following rules apply:
- if an arg value in FUNCARGSET is about to be torn down, the
mysetup-registered finalizers will execute as well.
- There will never be two active mysetup invocations.
Example 1, session scope::
@pytest.mark.funcarg(scope="session", params=[1,2])
def db(request):
request.addfinalizer(db_finalize)
@pytest.mark.setup
def mysetup(request, db):
request.addfinalizer(mysetup_finalize)
...
And a given test module:
def test_something():
...
def test_otherthing():
pass
Here is what happens::
db(request) executes with request.param == 1
mysetup(request, db) executes
test_something() executes
test_otherthing() executes
mysetup_finalize() executes
db_finalize() executes
db(request) executes with request.param == 2
mysetup(request, db) executes
test_something() executes
test_otherthing() executes
mysetup_finalize() executes
db_finalize() executes
Example 2, session/function scope::
@pytest.mark.funcarg(scope="session", params=[1,2])
def db(request):
request.addfinalizer(db_finalize)
@pytest.mark.setup(scope="function")
def mysetup(request, db):
...
request.addfinalizer(mysetup_finalize)
...
And a given test module:
def test_something():
...
def test_otherthing():
pass
Here is what happens::
db(request) executes with request.param == 1
mysetup(request, db) executes
test_something() executes
mysetup_finalize() executes
mysetup(request, db) executes
test_otherthing() executes
mysetup_finalize() executes
db_finalize() executes
db(request) executes with request.param == 2
mysetup(request, db) executes
test_something() executes
mysetup_finalize() executes
mysetup(request, db) executes
test_otherthing() executes
mysetup_finalize() executes
db_finalize() executes
Example 3 - funcargs session-mix
----------------------------------------
Similar with funcargs, an example::
@pytest.mark.funcarg(scope="session", params=[1,2])
def db(request):
request.addfinalizer(db_finalize)
@pytest.mark.funcarg(scope="function")
def table(request, db):
...
request.addfinalizer(table_finalize)
...
And a given test module:
def test_something(table):
...
def test_otherthing(table):
pass
def test_thirdthing():
pass
Here is what happens::
db(request) executes with param == 1
table(request, db)
test_something(table)
table_finalize()
table(request, db)
test_otherthing(table)
table_finalize()
db_finalize
db(request) executes with param == 2
table(request, db)
test_something(table)
table_finalize()
table(request, db)
test_otherthing(table)
table_finalize()
db_finalize
test_thirdthing()
Data structures
--------------------
pytest internally maintains a dict of active funcargs with cache, param,
finalizer, (scopeitem?) information:
active_funcargs = dict()
if a parametrized "db" is activated:
active_funcargs["db"] = FuncargInfo(dbvalue, paramindex,
FuncargFinalize(...), scopeitem)
if a test is torn down and the next test requires a differently
parametrized "db":
for argname in item.callspec.params:
if argname in active_funcargs:
funcarginfo = active_funcargs[argname]
if funcarginfo.param != item.callspec.params[argname]:
funcarginfo.callfinalizer()
del node2funcarg[funcarginfo.scopeitem]
del active_funcargs[argname]
nodes_to_be_torn_down = ...
for node in nodes_to_be_torn_down:
if node in node2funcarg:
argname = node2funcarg[node]
active_funcargs[argname].callfinalizer()
del node2funcarg[node]
del active_funcargs[argname]
if a test is setup requiring a "db" funcarg:
if "db" in active_funcargs:
return active_funcargs["db"][0]
funcarginfo = setup_funcarg()
active_funcargs["db"] = funcarginfo
node2funcarg[funcarginfo.scopeitem] = "db"
Implementation plan for resources
------------------------------------------
1. Revert FuncargRequest to the old form, unmerge item/request
(done)
2. make funcarg factories be discovered at collection time
3. Introduce funcarg marker
4. Introduce funcarg scope parameter
5. Introduce funcarg parametrize parameter
6. make setup functions be discovered at collection time
7. (Introduce a pytest_fixture_protocol/setup_funcargs hook)
methods and data structures
--------------------------------
A FuncarcManager holds all information about funcarg definitions
including parametrization and scope definitions. It implements
a pytest_generate_tests hook which performs parametrization as appropriate.
as a simple example, let's consider a tree where a test function requires
a "abc" funcarg and its factory defines it as parametrized and scoped
for Modules. When collections hits the function item, it creates
the metafunc object, and calls funcargdb.pytest_generate_tests(metafunc)
which looks up available funcarg factories and their scope and parametrization.
This information is equivalent to what can be provided today directly
at the function site and it should thus be relatively straight forward
to implement the additional way of defining parametrization/scoping.
conftest loading:
each funcarg-factory will populate the session.funcargmanager
When a test item is collected, it grows a dictionary
(funcargname2factorycalllist). A factory lookup is performed
for each required funcarg. The resulting factory call is stored
with the item. If a function is parametrized multiple items are
created with respective factory calls. Else if a factory is parametrized
multiple items and calls to the factory function are created as well.
At setup time, an item populates a funcargs mapping, mapping names
to values. If a value is funcarg factories are queried for a given item
test functions and setup functions are put in a class
which looks up required funcarg factories.

View File

@@ -34,15 +34,22 @@ class Junit(py.xml.Namespace):
# this dynamically instead of hardcoding it. The spec range of valid
# chars is: Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
# | [#x10000-#x10FFFF]
_illegal_unichrs = [(0x00, 0x08), (0x0B, 0x0C), (0x0E, 0x19),
(0xD800, 0xDFFF), (0xFDD0, 0xFFFF)]
_illegal_ranges = [unicode("%s-%s") % (unichr(low), unichr(high))
for (low, high) in _illegal_unichrs
_legal_chars = (0x09, 0x0A, 0x0d)
_legal_ranges = (
(0x20, 0x7E),
(0x80, 0xD7FF),
(0xE000, 0xFFFD),
(0x10000, 0x10FFFF),
)
_legal_xml_re = [unicode("%s-%s") % (unichr(low), unichr(high))
for (low, high) in _legal_ranges
if low < sys.maxunicode]
illegal_xml_re = re.compile(unicode('[%s]') %
unicode('').join(_illegal_ranges))
del _illegal_unichrs
del _illegal_ranges
_legal_xml_re = [unichr(x) for x in _legal_chars] + _legal_xml_re
illegal_xml_re = re.compile(unicode('[^%s]') %
unicode('').join(_legal_xml_re))
del _legal_chars
del _legal_ranges
del _legal_xml_re
def bin_xml_escape(arg):
def repl(matchobj):
@@ -51,20 +58,21 @@ def bin_xml_escape(arg):
return unicode('#x%02X') % i
else:
return unicode('#x%04X') % i
return illegal_xml_re.sub(repl, py.xml.escape(arg))
return py.xml.raw(illegal_xml_re.sub(repl, py.xml.escape(arg)))
def pytest_addoption(parser):
group = parser.getgroup("terminal reporting")
group.addoption('--junitxml', action="store", dest="xmlpath",
metavar="path", default=None,
group.addoption('--junitxml', '--junit-xml', action="store",
dest="xmlpath", metavar="path", default=None,
help="create junit-xml style report file at given path.")
group.addoption('--junitprefix', action="store", dest="junitprefix",
group.addoption('--junitprefix', '--junit-prefix', action="store",
metavar="str", default=None,
help="prepend prefix to classnames in junit-xml output")
def pytest_configure(config):
xmlpath = config.option.xmlpath
if xmlpath:
# prevent opening xmllog on slave nodes (xdist)
if xmlpath and not hasattr(config, 'slaveinput'):
config._xml = LogXML(xmlpath, config.option.junitprefix)
config.pluginmanager.register(config._xml)
@@ -75,51 +83,58 @@ def pytest_unconfigure(config):
config.pluginmanager.unregister(xml)
def mangle_testnames(names):
names = [x.replace(".py", "") for x in names if x != '()']
names[0] = names[0].replace("/", '.')
return names
class LogXML(object):
def __init__(self, logfile, prefix):
logfile = os.path.expanduser(os.path.expandvars(logfile))
self.logfile = os.path.normpath(logfile)
self.logfile = os.path.normpath(os.path.abspath(logfile))
self.prefix = prefix
self.tests = []
self.passed = self.skipped = 0
self.failed = self.errors = 0
def _opentestcase(self, report):
names = report.nodeid.split("::")
names[0] = names[0].replace("/", '.')
names = [x.replace(".py", "") for x in names if x != "()"]
names = mangle_testnames(report.nodeid.split("::"))
classnames = names[:-1]
if self.prefix:
classnames.insert(0, self.prefix)
self.tests.append(Junit.testcase(
classname=".".join(classnames),
name=names[-1],
name=bin_xml_escape(names[-1]),
time=getattr(report, 'duration', 0)
))
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)))
def append(self, obj):
self.tests[-1].append(obj)
def append_pass(self, report):
self.passed += 1
self._write_captured_output(report)
def append_failure(self, report):
#msg = str(report.longrepr.reprtraceback.extraline)
if "xfail" in report.keywords:
if hasattr(report, "wasxfail"):
self.append(
Junit.skipped(message="xfail-marked test passes unexpectedly"))
self.skipped += 1
else:
sec = dict(report.sections)
fail = Junit.failure(message="test failure")
fail.append(str(report.longrepr))
self.append(fail)
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)))
self.failed += 1
self._write_captured_output(report)
def append_collect_failure(self, report):
#msg = str(report.longrepr.reprtraceback.extraline)
@@ -139,8 +154,8 @@ class LogXML(object):
self.errors += 1
def append_skipped(self, report):
if "xfail" in report.keywords:
self.append(Junit.skipped(str(report.keywords['xfail']),
if hasattr(report, "wasxfail"):
self.append(Junit.skipped(str(report.wasxfail),
message="expected test failure"))
else:
filename, lineno, skipreason = report.longrepr
@@ -152,6 +167,7 @@ class LogXML(object):
message=skipreason
))
self.skipped += 1
self._write_captured_output(report)
def pytest_runtest_logreport(self, report):
if report.passed:
@@ -201,7 +217,7 @@ class LogXML(object):
logfile.write('<?xml version="1.0" encoding="utf-8"?>')
logfile.write(Junit.testsuite(
self.tests,
name="",
name="pytest",
errors=self.errors,
failures=self.failed,
skips=self.skipped,

View File

@@ -3,6 +3,13 @@
import py
import pytest, _pytest
import os, sys, imp
try:
from collections import MutableMapping as MappingMixin
except ImportError:
from UserDict import DictMixin as MappingMixin
from _pytest.runner import collect_one_node, Skipped
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
# exitcodes for the command line
@@ -10,6 +17,7 @@ EXIT_OK = 0
EXIT_TESTSFAILED = 1
EXIT_INTERRUPTED = 2
EXIT_INTERNALERROR = 3
EXIT_USAGEERROR = 4
name_re = py.std.re.compile("^[a-zA-Z_]\w*$")
@@ -26,20 +34,20 @@ def pytest_addoption(parser):
dest="exitfirst",
help="exit instantly on first error or failed test."),
group._addoption('--maxfail', metavar="num",
action="store", type="int", dest="maxfail", default=0,
action="store", type=int, dest="maxfail", default=0,
help="exit after first num failures or errors.")
group._addoption('--strict', action="store_true",
help="run pytest in strict mode, warnings become errors.")
group = parser.getgroup("collect", "collection")
group.addoption('--collectonly',
action="store_true", dest="collectonly",
group.addoption('--collectonly', '--collect-only', action="store_true",
help="only collect tests, don't execute them."),
group.addoption('--pyargs', action="store_true",
help="try to interpret all arguments as python packages.")
group.addoption("--ignore", action="append", metavar="path",
help="ignore path during collection (multi-allowed).")
# when changing this to --conf-cut-dir, config.py Conftest.setinitial
# needs upgrading as well
group.addoption('--confcutdir', dest="confcutdir", default=None,
metavar="dir",
help="only load conftest.py's relative to specified dir.")
@@ -65,30 +73,38 @@ def wrap_session(config, doit):
session.exitstatus = EXIT_OK
initstate = 0
try:
config.pluginmanager.do_configure(config)
initstate = 1
config.hook.pytest_sessionstart(session=session)
initstate = 2
doit(config, session)
except pytest.UsageError:
raise
except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo()
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED
except:
excinfo = py.code.ExceptionInfo()
config.pluginmanager.notify_exception(excinfo, config.option)
session.exitstatus = EXIT_INTERNALERROR
if excinfo.errisinstance(SystemExit):
sys.stderr.write("mainloop: caught Spurious SystemExit!\n")
if initstate >= 2:
config.hook.pytest_sessionfinish(session=session,
exitstatus=session.exitstatus or (session._testsfailed and 1))
if not session.exitstatus and session._testsfailed:
session.exitstatus = EXIT_TESTSFAILED
if initstate >= 1:
config.pluginmanager.do_unconfigure(config)
try:
config.do_configure()
initstate = 1
config.hook.pytest_sessionstart(session=session)
initstate = 2
doit(config, session)
except pytest.UsageError:
msg = sys.exc_info()[1].args[0]
sys.stderr.write("ERROR: %s\n" %(msg,))
session.exitstatus = EXIT_USAGEERROR
except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo()
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED
except:
excinfo = py.code.ExceptionInfo()
config.notify_exception(excinfo, config.option)
session.exitstatus = EXIT_INTERNALERROR
if excinfo.errisinstance(SystemExit):
sys.stderr.write("mainloop: caught Spurious SystemExit!\n")
else:
if session._testsfailed:
session.exitstatus = EXIT_TESTSFAILED
finally:
session.startdir.chdir()
if initstate >= 2:
config.hook.pytest_sessionfinish(
session=session,
exitstatus=session.exitstatus)
if initstate >= 1:
config.do_unconfigure()
config.pluginmanager.ensure_shutdown()
return session.exitstatus
def pytest_cmdline_main(config):
@@ -106,11 +122,18 @@ def pytest_collection(session):
def pytest_runtestloop(session):
if session.config.option.collectonly:
return True
for i, item in enumerate(session.items):
def getnextitem(i):
# this is a function to avoid python2
# keeping sys.exc_info set when calling into a test
# python2 keeps sys.exc_info till the frame is left
try:
nextitem = session.items[i+1]
return session.items[i+1]
except IndexError:
nextitem = None
return None
for i, item in enumerate(session.items):
nextitem = getnextitem(i)
item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
if session.shouldstop:
raise session.Interrupted(session.shouldstop)
@@ -129,8 +152,10 @@ class HookProxy:
def __init__(self, fspath, config):
self.fspath = fspath
self.config = config
def __getattr__(self, name):
hookmethod = getattr(self.config.hook, name)
def call_matching_hooks(**kwargs):
plugins = self.config._getmatchingplugins(self.fspath)
return hookmethod.pcall(plugins, **kwargs)
@@ -138,31 +163,83 @@ class HookProxy:
def compatproperty(name):
def fget(self):
# deprecated - use pytest.name
return getattr(pytest, name)
return property(fget, None, None,
"deprecated attribute %r, use pytest.%s" % (name,name))
return property(fget)
class NodeKeywords(MappingMixin):
def __init__(self, node):
self.node = node
self.parent = node.parent
self._markers = {node.name: True}
def __getitem__(self, key):
try:
return self._markers[key]
except KeyError:
if self.parent is None:
raise
return self.parent.keywords[key]
def __setitem__(self, key, value):
self._markers[key] = value
def __delitem__(self, key):
raise ValueError("cannot delete key in keywords dict")
def __iter__(self):
seen = set(self._markers)
if self.parent is not None:
seen.update(self.parent.keywords)
return iter(seen)
def __len__(self):
return len(self.__iter__())
def keys(self):
return list(self)
def __repr__(self):
return "<NodeKeywords for node %s>" % (self.node, )
class Node(object):
""" base class for all Nodes in the collection tree.
""" base class for Collector and Item the test collection tree.
Collector subclasses have children, Items are terminal nodes."""
def __init__(self, name, parent=None, config=None, session=None):
#: a unique name with the scope of the parent
#: a unique name within the scope of the parent node
self.name = name
#: the parent collector node.
self.parent = parent
#: the test config object
#: the pytest config object
self.config = config or parent.config
#: the collection this node is part of
#: the session this node is part of
self.session = session or parent.session
#: filesystem path where this node was collected from
#: filesystem path where this node was collected from (can be None)
self.fspath = getattr(parent, 'fspath', None)
self.ihook = self.session.gethookproxy(self.fspath)
self.keywords = {self.name: True}
#: keywords/markers collected from all scopes
self.keywords = NodeKeywords(self)
#: allow adding of extra keywords to use for matching
self.extra_keyword_matches = set()
#self.extrainit()
@property
def ihook(self):
""" fspath sensitive hook proxy used to call pytest hooks"""
return self.session.gethookproxy(self.fspath)
#def extrainit(self):
# """"extra initialization after Node is initialized. Implemented
# by some subclasses. """
Module = compatproperty("Module")
Class = compatproperty("Class")
@@ -180,25 +257,28 @@ class Node(object):
return cls
def __repr__(self):
return "<%s %r>" %(self.__class__.__name__, getattr(self, 'name', None))
return "<%s %r>" %(self.__class__.__name__,
getattr(self, 'name', None))
# methods for ordering nodes
@property
def nodeid(self):
""" a ::-separated string denoting its collection tree address. """
try:
return self._nodeid
except AttributeError:
self._nodeid = x = self._makeid()
return x
def _makeid(self):
return self.parent.nodeid + "::" + self.name
def __eq__(self, other):
if not isinstance(other, Node):
return False
return self.__class__ == other.__class__ and \
self.name == other.name and self.parent == other.parent
return (self.__class__ == other.__class__ and
self.name == other.name and self.parent == other.parent)
def __ne__(self, other):
return not self == other
@@ -241,12 +321,49 @@ class Node(object):
chain.reverse()
return chain
def add_marker(self, marker):
""" dynamically add a marker object to the node.
``marker`` can be a string or pytest.mark.* instance.
"""
from _pytest.mark import MarkDecorator
if isinstance(marker, py.builtin._basestring):
marker = MarkDecorator(marker)
elif not isinstance(marker, MarkDecorator):
raise ValueError("is not a string or pytest.mark.* Marker")
self.keywords[marker.name] = marker
def get_marker(self, name):
""" get a marker object from this node or None if
the node doesn't have a marker with that name. """
val = self.keywords.get(name, None)
if val is not None:
from _pytest.mark import MarkInfo, MarkDecorator
if isinstance(val, (MarkDecorator, MarkInfo)):
return val
def listextrakeywords(self):
""" Return a set of all extra keywords in self and any parents."""
extra_keywords = set()
item = self
for item in self.listchain():
extra_keywords.update(item.extra_keyword_matches)
return extra_keywords
def listnames(self):
return [x.name for x in self.listchain()]
def getplugins(self):
return self.config._getmatchingplugins(self.fspath)
def addfinalizer(self, fin):
""" register a function to be called when this node is finalized.
This method can only be called when this node is active
in a setup chain, for example during self.setup().
"""
self.session._setupstate.addfinalizer(fin, self)
def getparent(self, cls):
current = self
while current and not isinstance(current, cls):
@@ -257,6 +374,9 @@ class Node(object):
pass
def _repr_failure_py(self, excinfo, style=None):
fm = self.session._fixturemanager
if excinfo.errisinstance(fm.FixtureLookupError):
return excinfo.value.formatrepr()
if self.config.option.fulltrace:
style="long"
else:
@@ -278,6 +398,11 @@ class Collector(Node):
""" Collector instances create children through collect()
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. """
@@ -365,20 +490,21 @@ class Session(FSCollector):
__module__ = 'builtins' # for py3
def __init__(self, config):
super(Session, self).__init__(py.path.local(), parent=None,
config=config, session=self)
assert self.config.pluginmanager.register(self, name="session", prepend=True)
FSCollector.__init__(self, py.path.local(), parent=None,
config=config, session=self)
self.config.pluginmanager.register(self, name="session", prepend=True)
self._testsfailed = 0
self.shouldstop = False
self.trace = config.trace.root.get("collection")
self._norecursepatterns = config.getini("norecursedirs")
self.startdir = py.path.local()
def pytest_collectstart(self):
if self.shouldstop:
raise self.Interrupted(self.shouldstop)
def pytest_runtest_logreport(self, report):
if report.failed and 'xfail' not in getattr(report, 'keywords', []):
if report.failed and not hasattr(report, 'wasxfail'):
self._testsfailed += 1
maxfail = self.config.getvalue("maxfail")
if maxfail and self._testsfailed >= maxfail:
@@ -415,8 +541,7 @@ class Session(FSCollector):
parts = self._parsearg(arg)
self._initialparts.append(parts)
self._initialpaths.add(parts[0])
self.ihook.pytest_collectstart(collector=self)
rep = self.ihook.pytest_make_collect_report(collector=self)
rep = collect_one_node(self)
self.ihook.pytest_collectreport(report=rep)
self.trace.root.indent -= 1
if self._notfound:
@@ -453,7 +578,7 @@ class Session(FSCollector):
if path.check(dir=1):
assert not names, "invalid arg %r" %(arg,)
for path in path.visit(fil=lambda x: x.check(file=1),
rec=self._recurse, bf=True, sort=True):
rec=self._recurse, bf=True, sort=True):
for x in self._collectfile(path):
yield x
else:
@@ -465,13 +590,13 @@ class Session(FSCollector):
ihook = self.gethookproxy(path)
if not self.isinitpath(path):
if ihook.pytest_ignore_collect(path=path, config=self.config):
return ()
return ()
return ihook.pytest_collect_file(path=path, parent=self)
def _recurse(self, path):
ihook = self.gethookproxy(path.dirpath())
if ihook.pytest_ignore_collect(path=path, config=self.config):
return
return
for pat in self._norecursepatterns:
if path.check(fnmatch=pat):
return False
@@ -545,8 +670,7 @@ class Session(FSCollector):
resultnodes.append(node)
continue
assert isinstance(node, pytest.Collector)
node.ihook.pytest_collectstart(collector=node)
rep = node.ihook.pytest_make_collect_report(collector=node)
rep = collect_one_node(node)
if rep.passed:
has_matched = False
for x in rep.result:
@@ -567,10 +691,18 @@ class Session(FSCollector):
yield node
else:
assert isinstance(node, pytest.Collector)
node.ihook.pytest_collectstart(collector=node)
rep = node.ihook.pytest_make_collect_report(collector=node)
rep = collect_one_node(node)
if rep.passed:
for subnode in rep.result:
for x in self.genitems(subnode):
yield x
node.ihook.pytest_collectreport(report=rep)
def getfslineno(obj):
# xxx let decorators etc specify a sane ordering
if hasattr(obj, 'place_as'):
obj = obj.place_as
fslineno = py.code.getfslineno(obj)
assert isinstance(fslineno[1], int), obj
return fslineno

View File

@@ -1,43 +1,56 @@
""" generic mechanism for marking and selecting python functions. """
import pytest, py
import py
def pytest_namespace():
return {'mark': MarkGenerator()}
def pytest_addoption(parser):
group = parser.getgroup("general")
group._addoption('-k',
action="store", dest="keyword", default='', metavar="KEYWORDEXPR",
help="only run tests which match given keyword expression. "
"An expression consists of space-separated terms. "
"Each term must match. Precede a term with '-' to negate. "
"Terminate expression with ':' to make the first match match "
"all subsequent tests (usually file-order). ")
group._addoption(
'-k',
action="store", dest="keyword", default='', metavar="EXPRESSION",
help="only run tests which match the given substring expression. "
"An expression is a python evaluatable expression "
"where all names are substring-matched against test names "
"and their parent classes. Example: -k 'test_method or test "
"other' matches all test functions and classes whose name "
"contains 'test_method' or 'test_other'. "
"Additionally keywords are matched to classes and functions "
"containing extra names in their 'extra_keyword_matches' set, "
"as well as functions which have names assigned directly to them."
)
group._addoption("-m",
group._addoption(
"-m",
action="store", dest="markexpr", default="", metavar="MARKEXPR",
help="only run tests matching given mark expression. "
"example: -m 'mark1 and not mark2'."
)
)
group.addoption("--markers", action="store_true", help=
"show markers (builtin, plugin and per-project ones).")
group.addoption(
"--markers", action="store_true",
help="show markers (builtin, plugin and per-project ones)."
)
parser.addini("markers", "markers for test functions", 'linelist')
def pytest_cmdline_main(config):
if config.option.markers:
config.pluginmanager.do_configure(config)
config.do_configure()
tw = py.io.TerminalWriter()
for line in config.getini("markers"):
name, rest = line.split(":", 1)
tw.write("@pytest.mark.%s:" % name, bold=True)
tw.write("@pytest.mark.%s:" % name, bold=True)
tw.line(rest)
tw.line()
config.pluginmanager.do_unconfigure(config)
config.do_unconfigure()
return 0
pytest_cmdline_main.tryfirst = True
def pytest_collection_modifyitems(items, config):
keywordexpr = config.option.keyword
matchexpr = config.option.markexpr
@@ -51,7 +64,7 @@ def pytest_collection_modifyitems(items, config):
remaining = []
deselected = []
for colitem in items:
if keywordexpr and skipbykeyword(colitem, keywordexpr):
if keywordexpr and not matchkeyword(colitem, keywordexpr):
deselected.append(colitem)
else:
if selectuntil:
@@ -66,50 +79,75 @@ def pytest_collection_modifyitems(items, config):
config.hook.pytest_deselected(items=deselected)
items[:] = remaining
class BoolDict:
def __init__(self, mydict):
self._mydict = mydict
def __getitem__(self, name):
return name in self._mydict
def matchmark(colitem, matchexpr):
return eval(matchexpr, {}, BoolDict(colitem.obj.__dict__))
class MarkMapping:
"""Provides a local mapping for markers where item access
resolves to True if the marker is present. """
def __init__(self, keywords):
mymarks = set()
for key, value in keywords.items():
if isinstance(value, MarkInfo) or isinstance(value, MarkDecorator):
mymarks.add(key)
self._mymarks = mymarks
def __getitem__(self, name):
return name in self._mymarks
class KeywordMapping:
"""Provides a local mapping for keywords.
Given a list of names, map any substring of one of these names to True.
"""
def __init__(self, names):
self._names = names
def __getitem__(self, subname):
for name in self._names:
if subname in name:
return True
return False
def matchmark(colitem, markexpr):
"""Tries to match on any marker names, attached to the given colitem."""
return eval(markexpr, {}, MarkMapping(colitem.keywords))
def matchkeyword(colitem, keywordexpr):
"""Tries to match given keyword expression to given collector item.
Will match on the name of colitem, including the names of its parents.
Only matches names of items which are either a :class:`Class` or a
:class:`Function`.
Additionally, matches on names in the 'extra_keyword_matches' set of
any item, as well as names directly assigned to test functions.
"""
keywordexpr = keywordexpr.replace("-", "not ")
mapped_names = set()
# Add the names of the current item and any parent items
import pytest
for item in colitem.listchain():
if not isinstance(item, pytest.Instance):
mapped_names.add(item.name)
# Add the names added as extra keywords to current or parent items
for name in colitem.listextrakeywords():
mapped_names.add(name)
# Add the names attached to the current function through direct assignment
if hasattr(colitem, 'function'):
for name in colitem.function.__dict__:
mapped_names.add(name)
return eval(keywordexpr, {}, KeywordMapping(mapped_names))
def pytest_configure(config):
import pytest
if config.option.strict:
pytest.mark._config = config
def skipbykeyword(colitem, keywordexpr):
""" return True if they given keyword expression means to
skip this collector/item.
"""
if not keywordexpr:
return
itemkeywords = getkeywords(colitem)
for key in filter(None, keywordexpr.split()):
eor = key[:1] == '-'
if eor:
key = key[1:]
if not (eor ^ matchonekeyword(key, itemkeywords)):
return True
def getkeywords(node):
keywords = {}
while node is not None:
keywords.update(node.keywords)
node = node.parent
return keywords
def matchonekeyword(key, itemkeywords):
for elem in key.split("."):
for kw in itemkeywords:
if elem in kw:
break
else:
return False
return True
class MarkGenerator:
""" Factory for :class:`MarkDecorator` objects - exposed as
@@ -144,6 +182,7 @@ class MarkGenerator:
if name not in self._markers:
raise AttributeError("%r not a registered marker" % (name,))
class MarkDecorator:
""" A decorator for test functions and test classes. When applied
it will create :class:`MarkInfo` objects which may be
@@ -160,14 +199,18 @@ class MarkDecorator:
pass
"""
def __init__(self, name, args=None, kwargs=None):
self.markname = name
self.name = name
self.args = args or ()
self.kwargs = kwargs or {}
@property
def markname(self):
return self.name # for backward-compat (2.4.1 had this attr)
def __repr__(self):
d = self.__dict__.copy()
name = d.pop('markname')
return "<MarkDecorator %r %r>" %(name, d)
name = d.pop('name')
return "<MarkDecorator %r %r>" % (name, d)
def __call__(self, *args, **kwargs):
""" if passed a single callable argument: decorate it with mark info.
@@ -180,23 +223,26 @@ class MarkDecorator:
if hasattr(func, 'pytestmark'):
l = func.pytestmark
if not isinstance(l, list):
func.pytestmark = [l, self]
func.pytestmark = [l, self]
else:
l.append(self)
l.append(self)
else:
func.pytestmark = [self]
func.pytestmark = [self]
else:
holder = getattr(func, self.markname, None)
holder = getattr(func, self.name, None)
if holder is None:
holder = MarkInfo(self.markname, self.args, self.kwargs)
setattr(func, self.markname, holder)
holder = MarkInfo(
self.name, self.args, self.kwargs
)
setattr(func, self.name, holder)
else:
holder.add(self.args, self.kwargs)
return func
kw = self.kwargs.copy()
kw.update(kwargs)
args = self.args + args
return self.__class__(self.markname, args=args, kwargs=kw)
return self.__class__(self.name, args=args, kwargs=kw)
class MarkInfo:
""" Marking object created by :class:`MarkDecorator` instances. """
@@ -211,7 +257,8 @@ class MarkInfo:
def __repr__(self):
return "<MarkInfo %r args=%r kwargs=%r>" % (
self.name, self.args, self.kwargs)
self.name, self.args, self.kwargs
)
def add(self, args, kwargs):
""" add a MarkInfo with the given args and kwargs. """
@@ -223,4 +270,3 @@ class MarkInfo:
""" yield MarkInfo objects each relating to a marking-call. """
for args, kwargs in self._arglist:
yield MarkInfo(self.name, args, kwargs)

View File

@@ -24,6 +24,40 @@ def pytest_funcarg__monkeypatch(request):
request.addfinalizer(mpatch.undo)
return mpatch
def derive_importpath(import_path):
import pytest
if not isinstance(import_path, str) or "." not in import_path:
raise TypeError("must be absolute import path string, not %r" %
(import_path,))
rest = []
target = import_path
while target:
try:
obj = __import__(target, None, None, "__doc__")
except ImportError:
if "." not in target:
__tracebackhide__ = True
pytest.fail("could not import any sub part: %s" %
import_path)
target, name = target.rsplit(".", 1)
rest.append(name)
else:
assert rest
try:
while len(rest) > 1:
attr = rest.pop()
obj = getattr(obj, attr)
attr = rest[0]
getattr(obj, attr)
except AttributeError:
__tracebackhide__ = True
pytest.fail("object %r has no attribute %r" % (obj, attr))
return attr, obj
notset = object()
class monkeypatch:
@@ -33,24 +67,67 @@ class monkeypatch:
self._setitem = []
self._cwd = None
def setattr(self, obj, name, value, raising=True):
""" set attribute ``name`` on ``obj`` to ``value``, by default
raise AttributeEror if the attribute did not exist. """
oldval = getattr(obj, name, notset)
if raising and oldval is notset:
raise AttributeError("%r has no attribute %r" %(obj, name))
self._setattr.insert(0, (obj, name, oldval))
setattr(obj, name, value)
def setattr(self, target, name, value=notset, raising=True):
""" set attribute value on target, memorizing the old value.
By default raise AttributeError if the attribute did not exist.
def delattr(self, obj, name, raising=True):
""" delete attribute ``name`` from ``obj``, by default raise
AttributeError it the attribute did not previously exist. """
if not hasattr(obj, name):
For convenience you can specify a string as ``target`` which
will be interpreted as a dotted import path, with the last part
being the attribute name. Example:
``monkeypatch.setattr("os.getcwd", lambda x: "/")``
would set the ``getcwd`` function of the ``os`` module.
The ``raising`` value determines if the setattr should fail
if the attribute is not already present (defaults to True
which means it will raise).
"""
__tracebackhide__ = True
import inspect
if value is notset:
if not isinstance(target, str):
raise TypeError("use setattr(target, name, value) or "
"setattr(target, value) with target being a dotted "
"import string")
value = name
name, target = derive_importpath(target)
oldval = getattr(target, name, notset)
if raising and oldval is notset:
raise AttributeError("%r has no attribute %r" %(target, name))
# avoid class descriptors like staticmethod/classmethod
if inspect.isclass(target):
oldval = target.__dict__.get(name, notset)
self._setattr.insert(0, (target, name, oldval))
setattr(target, name, value)
def delattr(self, target, name=notset, raising=True):
""" delete attribute ``name`` from ``target``, by default raise
AttributeError it the attribute did not previously exist.
If no ``name`` is specified and ``target`` is a string
it will be interpreted as a dotted import path with the
last part being the attribute name.
If raising is set to false, the attribute is allowed to not
pre-exist.
"""
__tracebackhide__ = True
if name is notset:
if not isinstance(target, str):
raise TypeError("use delattr(target, name) or "
"delattr(target) with target being a dotted "
"import string")
name, target = derive_importpath(target)
if not hasattr(target, name):
if raising:
raise AttributeError(name)
else:
self._setattr.insert(0, (obj, name, getattr(obj, name, notset)))
delattr(obj, name)
self._setattr.insert(0, (target, name,
getattr(target, name, notset)))
delattr(target, name)
def setitem(self, dic, name, value):
""" set dictionary entry ``name`` to value. """

View File

@@ -1,21 +1,22 @@
""" run test suites written for nose. """
import pytest, py
import inspect
import sys
from _pytest import unittest
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: py.test.skip(str(call.excinfo.value)), call.when)
call2 = call.__class__(lambda:
pytest.skip(str(call.excinfo.value)), call.when)
call.excinfo = call2.excinfo
@pytest.mark.trylast
def pytest_runtest_setup(item):
if isinstance(item, (pytest.Function)):
if is_potential_nosetest(item):
if isinstance(item.parent, pytest.Generator):
gen = item.parent
if not hasattr(gen, '_nosegensetup'):
@@ -26,9 +27,11 @@ def pytest_runtest_setup(item):
if not call_optional(item.obj, 'setup'):
# call module level setup if there is no object level one
call_optional(item.parent.obj, 'setup')
#XXX this implies we only call teardown when setup worked
item.session._setupstate.addfinalizer((lambda: teardown_nose(item)), item)
def pytest_runtest_teardown(item):
if isinstance(item, pytest.Function):
def teardown_nose(item):
if is_potential_nosetest(item):
if not call_optional(item.obj, 'teardown'):
call_optional(item.parent.obj, 'teardown')
#if hasattr(item.parent, '_nosegensetup'):
@@ -36,12 +39,27 @@ def pytest_runtest_teardown(item):
# 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')
def is_potential_nosetest(item):
# extra check needed since we do not do nose style setup/teardown
# on direct unittest style classes
return isinstance(item, pytest.Function) and \
not isinstance(item, unittest.TestCaseFunction)
def call_optional(obj, name):
method = getattr(obj, name, None)
if method:
isfixture = hasattr(method, "_pytestfixturefunction")
if method is not None and not isfixture and py.builtin.callable(method):
# If there's any problems allow the exception to raise rather than
# silently ignoring them
method()

View File

@@ -2,7 +2,7 @@
import py, sys
class url:
base = "http://paste.pocoo.org"
base = "http://bpaste.net"
xmlrpc = base + "/xmlrpc/"
show = base + "/show/"
@@ -10,8 +10,8 @@ def pytest_addoption(parser):
group = parser.getgroup("terminal reporting")
group._addoption('--pastebin', metavar="mode",
action='store', dest="pastebin", default=None,
type="choice", choices=['failed', 'all'],
help="send failed|all info to Pocoo pastebin service.")
choices=['failed', 'all'],
help="send failed|all info to bpaste.net pastebin service.")
def pytest_configure(__multicall__, config):
import tempfile

View File

@@ -16,6 +16,12 @@ def pytest_configure(config):
if config.getvalue("usepdb"):
config.pluginmanager.register(PdbInvoke(), 'pdbinvoke')
old_trace = py.std.pdb.set_trace
def fin():
py.std.pdb.set_trace = old_trace
py.std.pdb.set_trace = pytest.set_trace
config._cleanup.append(fin)
class pytestPDB:
""" Pseudo PDB that defers to the real pdb. """
item = None
@@ -50,35 +56,49 @@ def pytest_make_collect_report(__multicall__, collector):
def pytest_runtest_makereport():
pytestPDB.item = None
class PdbInvoke:
@pytest.mark.tryfirst
def pytest_runtest_makereport(self, item, call, __multicall__):
rep = __multicall__.execute()
if not call.excinfo or \
call.excinfo.errisinstance(pytest.skip.Exception) or \
call.excinfo.errisinstance(py.std.bdb.BdbQuit):
return rep
if "xfail" in rep.keywords:
return rep
# we assume that the above execute() suspended capturing
# XXX we re-use the TerminalReporter's terminalwriter
# because this seems to avoid some encoding related troubles
# for not completely clear reasons.
tw = item.config.pluginmanager.getplugin("terminalreporter")._tw
tw.line()
tw.sep(">", "traceback")
rep.toterminal(tw)
tw.sep(">", "entering PDB")
# A doctest.UnexpectedException is not useful for post_mortem.
# Use the underlying exception instead:
if isinstance(call.excinfo.value, py.std.doctest.UnexpectedException):
tb = call.excinfo.value.exc_info[2]
else:
tb = call.excinfo._excinfo[2]
def pytest_exception_interact(self, node, call, report):
return _enter_pdb(node, call.excinfo, report)
def pytest_internalerror(self, excrepr, excinfo):
for line in str(excrepr).split("\n"):
sys.stderr.write("INTERNALERROR> %s\n" %line)
sys.stderr.flush()
tb = _postmortem_traceback(excinfo)
post_mortem(tb)
rep._pdbshown = True
return rep
def _enter_pdb(node, excinfo, rep):
# XXX we re-use the TerminalReporter's terminalwriter
# because this seems to avoid some encoding related troubles
# for not completely clear reasons.
tw = node.config.pluginmanager.getplugin("terminalreporter")._tw
tw.line()
tw.sep(">", "traceback")
rep.toterminal(tw)
tw.sep(">", "entering PDB")
tb = _postmortem_traceback(excinfo)
post_mortem(tb)
rep._pdbshown = True
return 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):
return excinfo.value.exc_info[2]
else:
return excinfo._excinfo[2]
def _find_last_non_hidden_frame(stack):
i = max(0, len(stack) - 1)
while i and stack[i][0].f_locals.get("__tracebackhide__", False):
i -= 1
return i
def post_mortem(t):
pdb = py.std.pdb
@@ -86,9 +106,7 @@ def post_mortem(t):
def get_stack(self, f, t):
stack, i = pdb.Pdb.get_stack(self, f, t)
if f is None:
i = max(0, len(stack) - 1)
while i and stack[i][0].f_locals.get("__tracebackhide__", False):
i-=1
i = _find_last_non_hidden_frame(stack)
return stack, i
p = Pdb()
p.reset()

View File

@@ -2,14 +2,20 @@
import py, pytest
import sys, os
import codecs
import re
import inspect
import time
from fnmatch import fnmatch
from _pytest.main import Session, EXIT_OK
from py.builtin import print_
from _pytest.core import HookRelay
def get_public_names(l):
"""Only return names from iterator l without a leading underscore."""
return [x for x in l if x[0] != "_"]
def pytest_addoption(parser):
group = parser.getgroup("pylib")
group.addoption('--no-tools-on-path',
@@ -76,7 +82,8 @@ class HookRecorder:
def finish_recording(self):
for recorder in self._recorders.values():
self._pluginmanager.unregister(recorder)
if self._pluginmanager.isregistered(recorder):
self._pluginmanager.unregister(recorder)
self._recorders.clear()
def _makecallparser(self, method):
@@ -194,10 +201,7 @@ class TmpTestdir:
except py.error.EEXIST:
continue
break
# we need to create another subdir
# because Directory.collect() currently loads
# conftest.py from sibling directories
self.tmpdir = tmpdir.mkdir(name)
self.tmpdir = tmpdir
self.plugins = []
self._syspathremove = []
self.chdir() # always chdir
@@ -244,8 +248,10 @@ 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)).lstrip()
p.write(source.encode("utf-8"), "wb")
source = py.builtin._totext(py.code.Source(value)).strip()
content = source.encode("utf-8") # + "\n"
#content = content.rstrip() + "\n"
p.write(content, "wb")
if ret is None:
ret = p
return ret
@@ -318,7 +324,7 @@ class TmpTestdir:
# used from runner functional tests
item = self.getitem(source)
# the test class where we are called from wants to provide the runner
testclassinstance = py.builtin._getimself(self.request.function)
testclassinstance = self.request.instance
runner = testclassinstance.getrunner()
return runner(item)
@@ -355,7 +361,7 @@ class TmpTestdir:
if not plugins:
plugins = []
plugins.append(Collect())
ret = self.pytestmain(list(args), plugins=[Collect()])
ret = pytest.main(list(args), plugins=plugins)
reprec = rec[0]
reprec.ret = ret
assert len(rec) == 1
@@ -368,30 +374,33 @@ class TmpTestdir:
break
else:
args.append("--basetemp=%s" % self.tmpdir.dirpath('basetemp'))
import _pytest.core
config = _pytest.core._prepareconfig(args, self.plugins)
# the in-process pytest invocation needs to avoid leaking FDs
# so we register a "reset_capturings" callmon the capturing manager
# and make sure it gets called
config._cleanup.append(
config.pluginmanager.getplugin("capturemanager").reset_capturings)
import _pytest.config
self.request.addfinalizer(
lambda: _pytest.config.pytest_unconfigure(config))
config = _pytest.config._prepareconfig(args, self.plugins)
# we don't know what the test will do with this half-setup config
# object and thus we make sure it gets unconfigured properly in any
# case (otherwise capturing could still be active, for example)
def ensure_unconfigure():
if hasattr(config.pluginmanager, "_config"):
config.pluginmanager.do_unconfigure(config)
config.pluginmanager.ensure_shutdown()
self.request.addfinalizer(ensure_unconfigure)
return config
def parseconfigure(self, *args):
config = self.parseconfig(*args)
config.pluginmanager.do_configure(config)
config.do_configure()
self.request.addfinalizer(lambda:
config.pluginmanager.do_unconfigure(config))
config.do_unconfigure())
return config
def getitem(self, source, funcname="test_func"):
for item in self.getitems(source):
items = self.getitems(source)
for item in items:
if item.name == funcname:
return item
assert 0, "%r item not found in module:\n%s" %(funcname, source)
assert 0, "%r item not found in module:\n%s\nitems: %s" %(
funcname, source, items)
def getitems(self, source):
modcol = self.getmodulecol(source)
@@ -417,18 +426,8 @@ class TmpTestdir:
str(os.getcwd()), env.get('PYTHONPATH', '')]))
kw['env'] = env
#print "env", env
return py.std.subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw)
def pytestmain(self, *args, **kwargs):
class ResetCapturing:
@pytest.mark.trylast
def pytest_unconfigure(self, config):
capman = config.pluginmanager.getplugin("capturemanager")
capman.reset_capturings()
plugins = kwargs.setdefault("plugins", [])
rc = ResetCapturing()
plugins.append(rc)
return pytest.main(*args, **kwargs)
return py.std.subprocess.Popen(cmdargs,
stdout=stdout, stderr=stderr, **kw)
def run(self, *cmdargs):
return self._run(*cmdargs)
@@ -438,28 +437,35 @@ class TmpTestdir:
p1 = self.tmpdir.join("stdout")
p2 = self.tmpdir.join("stderr")
print_("running", cmdargs, "curdir=", py.path.local())
f1 = p1.open("wb")
f2 = p2.open("wb")
now = time.time()
popen = self.popen(cmdargs, stdout=f1, stderr=f2,
close_fds=(sys.platform != "win32"))
ret = popen.wait()
f1.close()
f2.close()
out = p1.read("rb")
out = getdecoded(out).splitlines()
err = p2.read("rb")
err = getdecoded(err).splitlines()
def dump_lines(lines, fp):
try:
for line in lines:
py.builtin.print_(line, file=fp)
except UnicodeEncodeError:
print("couldn't print to %s because of encoding" % (fp,))
dump_lines(out, sys.stdout)
dump_lines(err, sys.stderr)
f1 = codecs.open(str(p1), "w", encoding="utf8")
f2 = codecs.open(str(p2), "w", encoding="utf8")
try:
now = time.time()
popen = self.popen(cmdargs, stdout=f1, stderr=f2,
close_fds=(sys.platform != "win32"))
ret = popen.wait()
finally:
f1.close()
f2.close()
f1 = codecs.open(str(p1), "r", encoding="utf8")
f2 = codecs.open(str(p2), "r", encoding="utf8")
try:
out = f1.read().splitlines()
err = f2.read().splitlines()
finally:
f1.close()
f2.close()
self._dump_lines(out, sys.stdout)
self._dump_lines(err, sys.stderr)
return RunResult(ret, out, err, time.time()-now)
def _dump_lines(self, lines, fp):
try:
for line in lines:
py.builtin.print_(line, file=fp)
except UnicodeEncodeError:
print("couldn't print to %s because of encoding" % (fp,))
def runpybin(self, scriptname, *args):
fullargs = self._getpybinargs(scriptname) + args
return self.run(*fullargs)
@@ -520,6 +526,8 @@ class TmpTestdir:
pytest.skip("pypy-64 bit not supported")
if sys.platform == "darwin":
pytest.xfail("pexpect does not work reliably on darwin?!")
if sys.platform.startswith("freebsd"):
pytest.xfail("pexpect does not work reliably on freebsd")
logfile = self.tmpdir.join("spawn.out")
child = pexpect.spawn(cmd, logfile=logfile.open("w"))
child.timeout = expect_timeout
@@ -586,9 +594,10 @@ class ReportRecorder(object):
passed = []
skipped = []
failed = []
for rep in self.getreports("pytest_runtest_logreport"):
for rep in self.getreports(
"pytest_collectreport pytest_runtest_logreport"):
if rep.passed:
if rep.when == "call":
if getattr(rep, "when", None) == "call":
passed.append(rep)
elif rep.skipped:
skipped.append(rep)
@@ -651,6 +660,12 @@ class LineMatcher:
else:
raise ValueError("line %r not found in output" % line)
def get_lines_after(self, fnline):
for i, line in enumerate(self.lines):
if fnline == line or fnmatch(line, fnline):
return self.lines[i+1:]
raise ValueError("line %r not found in output" % fnline)
def fnmatch_lines(self, lines2):
def show(arg1, arg2):
py.builtin.print_(arg1, arg2, file=py.std.sys.stderr)

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,14 @@
""" recording warnings during test function execution. """
import py
import sys, os
import sys
def pytest_funcarg__recwarn(request):
"""Return a WarningsRecorder instance that provides these methods:
* ``pop(category=None)``: return last warning matching the category.
* ``clear()``: clear list of warnings
See http://docs.python.org/library/warnings.html for information
on warning categories.
"""

View File

@@ -1,10 +1,12 @@
""" (disabled by default) create result information in a plain text file. """
""" log machine-parseable test session result information in a plain
text file.
"""
import py
def pytest_addoption(parser):
group = parser.getgroup("terminal reporting", "resultlog plugin options")
group.addoption('--resultlog', action="store", dest="resultlog",
group.addoption('--resultlog', '--result-log', action="store",
metavar="path", default=None,
help="path for machine-readable result log.")

View File

@@ -1,6 +1,7 @@
""" basic collect and runtest protocol implementations """
import py, sys, time
import py, sys
from time import time
from py._code.code import TerminalRepr
def pytest_namespace():
@@ -17,7 +18,7 @@ def pytest_namespace():
def pytest_addoption(parser):
group = parser.getgroup("terminal reporting", "reporting", after="general")
group.addoption('--durations',
action="store", type="int", default=None, metavar="N",
action="store", type=int, default=None, metavar="N",
help="show N slowest setup/test durations (N=0 for all)."),
def pytest_terminal_summary(terminalreporter):
@@ -62,12 +63,20 @@ def pytest_runtest_protocol(item, nextitem):
return True
def runtestprotocol(item, log=True, nextitem=None):
hasrequest = hasattr(item, "_request")
if hasrequest and not item._request:
item._initrequest()
rep = call_and_report(item, "setup", log)
reports = [rep]
if rep.passed:
reports.append(call_and_report(item, "call", log))
reports.append(call_and_report(item, "teardown", log,
nextitem=nextitem))
# after all teardown hooks have been called
# want funcargs and request info to go away
if hasrequest:
item._request = False
item.funcargs = None
return reports
def pytest_runtest_setup(item):
@@ -99,8 +108,16 @@ def call_and_report(item, when, log=True, **kwds):
report = hook.pytest_runtest_makereport(item=item, call=call)
if log:
hook.pytest_runtest_logreport(report=report)
if check_interactive_exception(call, report):
hook.pytest_exception_interact(node=item, call=call, report=report)
return report
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))
def call_runtest_hook(item, when, **kwds):
hookname = "pytest_runtest_" + when
ihook = getattr(item.ihook, hookname)
@@ -114,7 +131,7 @@ class CallInfo:
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time.time()
self.start = time()
try:
try:
self.result = func()
@@ -123,7 +140,7 @@ class CallInfo:
except:
self.excinfo = py.code.ExceptionInfo()
finally:
self.stop = time.time()
self.stop = time()
def __repr__(self):
if self.excinfo:
@@ -154,7 +171,10 @@ class BaseReport(object):
if hasattr(longrepr, 'toterminal'):
longrepr.toterminal(out)
else:
out.line(str(longrepr))
try:
out.line(longrepr)
except UnicodeEncodeError:
out.line("<unprintable longrepr>")
passed = property(lambda x: x.outcome == "passed")
failed = property(lambda x: x.outcome == "failed")
@@ -186,7 +206,8 @@ def pytest_runtest_makereport(item, call):
if call.when == "call":
longrepr = item.repr_failure(excinfo)
else: # exception in setup or teardown
longrepr = item._repr_failure_py(excinfo)
longrepr = item._repr_failure_py(excinfo,
style=item.config.option.tbstyle)
return TestReport(item.nodeid, item.location,
keywords, outcome, longrepr, when,
duration=duration)
@@ -245,7 +266,7 @@ def pytest_make_collect_report(collector):
if not call.excinfo:
outcome = "passed"
else:
if call.excinfo.errisinstance(py.test.skip.Exception):
if call.excinfo.errisinstance(collector.skip_exceptions):
outcome = "skipped"
r = collector._repr_failure_py(call.excinfo, "line").reprcrash
longrepr = (str(r.path), r.lineno, r.message)
@@ -255,8 +276,11 @@ def pytest_make_collect_report(collector):
if not hasattr(errorinfo, "toterminal"):
errorinfo = CollectErrorRepr(errorinfo)
longrepr = errorinfo
return CollectReport(collector.nodeid, outcome, longrepr,
rep = CollectReport(collector.nodeid, outcome, longrepr,
getattr(call, 'result', None))
rep.call = call # see collect_one_node
return rep
class CollectReport(BaseReport):
def __init__(self, nodeid, outcome, longrepr, result, sections=(), **extra):
@@ -279,7 +303,7 @@ class CollectErrorRepr(TerminalRepr):
def __init__(self, msg):
self.longrepr = msg
def toterminal(self, out):
out.line(str(self.longrepr), red=True)
out.line(self.longrepr, red=True)
class SetupState(object):
""" shared state for setting up/tearing down test items or collectors. """
@@ -291,6 +315,8 @@ 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
@@ -308,15 +334,17 @@ class SetupState(object):
def _teardown_with_finalization(self, colitem):
self._callfinalizers(colitem)
if colitem:
if hasattr(colitem, "teardown"):
colitem.teardown()
for colitem in self._finalizers:
assert colitem is None or colitem in self.stack
assert colitem is None or colitem in self.stack \
or isinstance(colitem, tuple)
def teardown_all(self):
while self.stack:
self._pop_and_teardown()
self._teardown_with_finalization(None)
for key in list(self._finalizers):
self._teardown_with_finalization(key)
assert not self._finalizers
def teardown_exact(self, item, nextitem):
@@ -347,6 +375,16 @@ class SetupState(object):
col._prepare_exc = sys.exc_info()
raise
def collect_one_node(collector):
ihook = collector.ihook
ihook.pytest_collectstart(collector=collector)
rep = ihook.pytest_make_collect_report(collector=collector)
call = rep.__dict__.pop("call", None)
if call and check_interactive_exception(call, rep):
ihook.pytest_exception_interact(node=collector, call=call, report=rep)
return rep
# =============================================================
# Test OutcomeExceptions and helpers for creating them.
@@ -356,6 +394,7 @@ class OutcomeException(Exception):
contain info about test and collection outcomes.
"""
def __init__(self, msg=None, pytrace=True):
Exception.__init__(self, msg)
self.msg = msg
self.pytrace = pytrace
@@ -401,7 +440,9 @@ skip.Exception = Skipped
def fail(msg="", pytrace=True):
""" explicitely fail an currently-executing test with the given Message.
if @pytrace is not True the msg represents the full failure information.
:arg pytrace: if false the msg represents the full failure information
and no python traceback will be reported.
"""
__tracebackhide__ = True
raise Failed(msg=msg, pytrace=pytrace)
@@ -416,9 +457,10 @@ def importorskip(modname, minversion=None):
__tracebackhide__ = True
compile(modname, '', 'eval') # to catch syntaxerrors
try:
mod = __import__(modname, None, None, ['__doc__'])
__import__(modname)
except ImportError:
py.test.skip("could not import %r" %(modname,))
mod = sys.modules[modname]
if minversion is None:
return mod
verattr = getattr(mod, '__version__', None)

View File

@@ -11,17 +11,18 @@ def pytest_addoption(parser):
def pytest_configure(config):
config.addinivalue_line("markers",
"skipif(*conditions): skip the given test function if evaluation "
"of all conditions has a True value. Evaluation happens within the "
"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. "
"skips the test if we are on the win32 platform. see "
"http://pytest.org/latest/skipping.html"
)
config.addinivalue_line("markers",
"xfail(*conditions, reason=None, run=True): mark the the test function "
"as an expected failure. Optionally specify a reason and run=False "
"if you don't even want to execute the test function. Any positional "
"condition strings will be evaluated (like with skipif) and if one is "
"False the marker will not be applied."
"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"
)
def pytest_namespace():
@@ -85,10 +86,14 @@ class MarkEvaluator:
self.result = False
for expr in self.holder.args:
self.expr = expr
if isinstance(expr, str):
if isinstance(expr, py.builtin._basestring):
result = cached_eval(self.item.config, expr, d)
else:
pytest.fail("expression is not a string")
if self.get("reason") is None:
# XXX better be checked at collection time
pytest.fail("you need to specify reason=STRING "
"when using booleans as conditions.")
result = bool(expr)
if result:
self.result = True
self.expr = expr
@@ -110,6 +115,7 @@ class MarkEvaluator:
return expl
@pytest.mark.tryfirst
def pytest_runtest_setup(item):
if not isinstance(item, pytest.Function):
return
@@ -132,6 +138,14 @@ def check_xfail_no_run(item):
def pytest_runtest_makereport(__multicall__, item, call):
if not isinstance(item, pytest.Function):
return
# unitttest special case, see setting of _unexpectedsuccess
if hasattr(item, '_unexpectedsuccess'):
rep = __multicall__.execute()
if rep.when == "call":
# we need to translate into how py.test 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)):
evalxfail = getattr(item, '_evalxfail', None)
@@ -140,27 +154,27 @@ def pytest_runtest_makereport(__multicall__, item, call):
if call.excinfo and call.excinfo.errisinstance(py.test.xfail.Exception):
if not item.config.getvalue("runxfail"):
rep = __multicall__.execute()
rep.keywords['xfail'] = "reason: " + call.excinfo.value.msg
rep.wasxfail = "reason: " + call.excinfo.value.msg
rep.outcome = "skipped"
return rep
rep = __multicall__.execute()
evalxfail = item._evalxfail
if not item.config.option.runxfail:
if evalxfail.wasvalid() and evalxfail.istrue():
if call.excinfo:
rep.outcome = "skipped"
rep.keywords['xfail'] = evalxfail.getexplanation()
elif call.when == "call":
rep.outcome = "failed"
rep.keywords['xfail'] = evalxfail.getexplanation()
return rep
if 'xfail' in rep.keywords:
del rep.keywords['xfail']
if not rep.skipped:
if not item.config.option.runxfail:
if evalxfail.wasvalid() and evalxfail.istrue():
if call.excinfo:
rep.outcome = "skipped"
elif call.when == "call":
rep.outcome = "failed"
else:
return rep
rep.wasxfail = evalxfail.getexplanation()
return rep
return rep
# called by terminalreporter progress reporting
def pytest_report_teststatus(report):
if 'xfail' in report.keywords:
if hasattr(report, "wasxfail"):
if report.skipped:
return "xfailed", "x", "xfail"
elif report.failed:
@@ -207,7 +221,7 @@ def show_xfailed(terminalreporter, lines):
if xfailed:
for rep in xfailed:
pos = rep.nodeid
reason = rep.keywords['xfail']
reason = rep.wasxfail
lines.append("XFAIL %s" % (pos,))
if reason:
lines.append(" " + str(reason))
@@ -217,7 +231,7 @@ def show_xpassed(terminalreporter, lines):
if xpassed:
for rep in xpassed:
pos = rep.nodeid
reason = rep.keywords['xfail']
reason = rep.wasxfail
lines.append("XPASS %s %s" %(pos, reason))
def cached_eval(config, expr, d):

View File

@@ -6,13 +6,16 @@ sources = """
import sys
import base64
import zlib
import imp
class DictImporter(object):
def __init__(self, sources):
self.sources = sources
def find_module(self, fullname, path=None):
if fullname == "argparse" and sys.version_info >= (2,7):
# we were generated with <python2.7 (which pulls in argparse)
# but we are running now on a stdlib which has it, so use that.
return None
if fullname in self.sources:
return self
if fullname + '.__init__' in self.sources:
@@ -57,7 +60,7 @@ if __name__ == "__main__":
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
importer = DictImporter(sources)
sys.meta_path.append(importer)
sys.meta_path.insert(0, importer)
entry = "@ENTRY@"
do_exec(entry, locals())

View File

@@ -2,7 +2,8 @@
This is a good source for looking at the various reporting hooks.
"""
import pytest, py
import pytest
import py
import sys
import os
@@ -11,7 +12,7 @@ def pytest_addoption(parser):
group._addoption('-v', '--verbose', action="count",
dest="verbose", default=0, help="increase verbosity."),
group._addoption('-q', '--quiet', action="count",
dest="quiet", default=0, help="decreate verbosity."),
dest="quiet", default=0, help="decrease verbosity."),
group._addoption('-r',
action="store", dest="reportchars", default=None, metavar="chars",
help="show extra test summary info as specified by chars (f)ailed, "
@@ -24,28 +25,15 @@ def pytest_addoption(parser):
help="(deprecated, use -r)")
group._addoption('--tb', metavar="style",
action="store", dest="tbstyle", default='long',
type="choice", choices=['long', 'short', 'no', 'line', 'native'],
choices=['long', 'short', 'no', 'line', 'native'],
help="traceback print mode (long/short/line/native/no).")
group._addoption('--fulltrace',
action="store_true", dest="fulltrace", default=False,
group._addoption('--fulltrace', '--full-trace',
action="store_true", default=False,
help="don't cut any tracebacks (default is to cut).")
def pytest_configure(config):
config.option.verbose -= config.option.quiet
# we try hard to make printing resilient against
# later changes on FD level.
stdout = py.std.sys.stdout
if hasattr(os, 'dup') and hasattr(stdout, 'fileno'):
try:
newfd = os.dup(stdout.fileno())
#print "got newfd", newfd
except ValueError:
pass
else:
stdout = os.fdopen(newfd, stdout.mode, 1)
config._cleanup.append(lambda: stdout.close())
reporter = TerminalReporter(config, stdout)
reporter = TerminalReporter(config, sys.stdout)
config.pluginmanager.register(reporter, 'terminalreporter')
if config.option.debug or config.option.traceconfig:
def mywriter(tags, args):
@@ -94,24 +82,24 @@ class TerminalReporter:
self._numcollected = 0
self.stats = {}
self.curdir = py.path.local()
self.startdir = self.curdir = py.path.local()
if file is None:
file = py.std.sys.stdout
self._tw = py.io.TerminalWriter(file)
self._tw = self.writer = py.io.TerminalWriter(file)
self.currentfspath = None
self.reportchars = getreportopt(config)
self.hasmarkup = self._tw.hasmarkup
def hasopt(self, char):
char = {'xfailed': 'x', 'skipped': 's'}.get(char,char)
char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
return char in self.reportchars
def write_fspath_result(self, fspath, res):
if fspath != self.currentfspath:
self.currentfspath = fspath
#fspath = self.curdir.bestrelpath(fspath)
#fspath = self.startdir.bestrelpath(fspath)
self._tw.line()
#relpath = self.curdir.bestrelpath(fspath)
#relpath = self.startdir.bestrelpath(fspath)
self._tw.write(fspath + " ")
self._tw.write(res)
@@ -145,6 +133,12 @@ class TerminalReporter:
self.ensure_newline()
self._tw.sep(sep, title, **markup)
def section(self, title, sep="=", **kw):
self._tw.sep(sep, title, **kw)
def line(self, msg, **kw):
self._tw.line(msg, **kw)
def pytest_internalerror(self, excrepr):
for line in str(excrepr).split("\n"):
self.write_line("INTERNALERROR> " + line)
@@ -152,7 +146,7 @@ class TerminalReporter:
def pytest_plugin_registered(self, plugin):
if self.config.option.traceconfig:
msg = "PLUGIN registered: %s" %(plugin,)
msg = "PLUGIN registered: %s" % (plugin,)
# XXX this event may happen during setup/teardown time
# which unfortunately captures our output here
# which garbles our output if we use self.write_line
@@ -176,6 +170,7 @@ class TerminalReporter:
res = self.config.hook.pytest_report_teststatus(report=rep)
cat, letter, word = res
self.stats.setdefault(cat, []).append(rep)
self._tests_ran = True
if not letter and not word:
# probably passed setup/teardown
return
@@ -207,7 +202,7 @@ class TerminalReporter:
self.currentfspath = -2
def pytest_collection(self):
if not self.hasmarkup:
if not self.hasmarkup and self.config.option.verbose >= 1:
self.write("collecting ... ", bold=True)
def pytest_collectreport(self, report):
@@ -222,6 +217,9 @@ class TerminalReporter:
self.report_collect()
def report_collect(self, final=False):
if self.config.option.verbose < 0:
return
errors = len(self.stats.get('error', []))
skipped = len(self.stats.get('skipped', []))
if final:
@@ -243,6 +241,7 @@ class TerminalReporter:
def pytest_collection_modifyitems(self):
self.report_collect(True)
@pytest.mark.trylast
def pytest_sessionstart(self, session):
self._sessionstarttime = py.std.time.time()
if not self.showheader:
@@ -258,11 +257,23 @@ class TerminalReporter:
getattr(self.config.option, 'pastebin', None):
msg += " -- " + str(sys.executable)
self.write_line(msg)
lines = self.config.hook.pytest_report_header(config=self.config)
lines = self.config.hook.pytest_report_header(
config=self.config, startdir=self.startdir)
lines.reverse()
for line in flatten(lines):
self.write_line(line)
def pytest_report_header(self, config):
plugininfo = config.pluginmanager._plugin_distinfo
if plugininfo:
l = []
for dist, plugin in plugininfo:
name = dist.project_name
if name.startswith("pytest-"):
name = name[7:]
l.append(name)
return "plugins: %s" % ", ".join(l)
def pytest_collection_finish(self, session):
if self.config.option.collectonly:
self._printcollecteditems(session.items)
@@ -307,15 +318,16 @@ class TerminalReporter:
stack.append(col)
#if col.name == "()":
# continue
indent = (len(stack)-1) * " "
self._tw.line("%s%s" %(indent, col))
indent = (len(stack) - 1) * " "
self._tw.line("%s%s" % (indent, col))
def pytest_sessionfinish(self, exitstatus, __multicall__):
__multicall__.execute()
self._tw.line("")
if exitstatus in (0, 1, 2):
if exitstatus in (0, 1, 2, 4):
self.summary_errors()
self.summary_failures()
self.summary_hints()
self.config.hook.pytest_terminal_summary(terminalreporter=self)
if exitstatus == 2:
self._report_keyboardinterrupt()
@@ -381,6 +393,11 @@ 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_failures(self):
if self.config.option.tbstyle != "no":
reports = self.getreports('failed')
@@ -425,7 +442,7 @@ class TerminalReporter:
def summary_stats(self):
session_duration = py.std.time.time() - self._sessionstarttime
keys = "failed passed skipped deselected".split()
keys = "failed passed skipped deselected xfailed xpassed".split()
for key in self.stats.keys():
if key not in keys:
keys.append(key)
@@ -434,14 +451,20 @@ class TerminalReporter:
if key: # setup/teardown reports have an empty key, ignore them
val = self.stats.get(key, None)
if val:
parts.append("%d %s" %(len(val), key))
parts.append("%d %s" % (len(val), key))
line = ", ".join(parts)
# XXX coloring
msg = "%s in %.2f seconds" %(line, session_duration)
if self.verbosity >= 0:
self.write_sep("=", msg, bold=True)
msg = "%s in %.2f seconds" % (line, session_duration)
markup = {'bold': True}
if 'failed' in self.stats or 'error' in self.stats:
markup = {'red': True, 'bold': True}
else:
self.write_line(msg, bold=True)
markup = {'green': True, 'bold': True}
if self.verbosity >= 0:
self.write_sep("=", msg, **markup)
if self.verbosity == -1:
self.write_line(msg, **markup)
def summary_deselected(self):
if 'deselected' in self.stats:
@@ -452,8 +475,9 @@ class TerminalReporter:
m = self.config.option.markexpr
if m:
l.append("-m %r" % m)
self.write_sep("=", "%d tests deselected by %r" %(
len(self.stats['deselected']), " ".join(l)), bold=True)
if l:
self.write_sep("=", "%d tests deselected by %r" % (
len(self.stats['deselected']), " ".join(l)), bold=True)
def repr_pythonversion(v=None):
if v is None:

View File

@@ -40,7 +40,7 @@ class TempdirHandler:
basetemp.mkdir()
else:
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
self._basetemp = t = basetemp
self._basetemp = t = basetemp.realpath()
self.trace("new basetemp", t)
return t
@@ -54,15 +54,18 @@ def pytest_configure(config):
mp.setattr(config, '_tmpdirhandler', t, raising=False)
mp.setattr(pytest, 'ensuretemp', t.ensuretemp, raising=False)
def pytest_funcarg__tmpdir(request):
@pytest.fixture
def tmpdir(request):
"""return a temporary directory path object
which is unique to each test function invocation,
created as a sub directory of the base temporary
directory. The returned object is a `py.path.local`_
path object.
"""
name = request._pyfuncitem.name
name = request.node.name
name = py.std.re.sub("[\W]", "_", name)
MAXVAL = 30
if len(name) > MAXVAL:
name = name[:MAXVAL]
x = request.config._tmpdirhandler.mktemp(name, numbered=True)
return x

View File

@@ -1,29 +1,51 @@
""" discovery and running of std-library "unittest" style tests. """
import pytest, py
import sys, pdb
import sys
# for transfering markers
from _pytest.python import transfer_markers
def pytest_pycollect_makeitem(collector, name, obj):
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
return # nobody can have derived unittest.TestCase
try:
isunit = issubclass(obj, unittest.TestCase)
return issubclass(obj, unittest.TestCase)
except KeyboardInterrupt:
raise
except Exception:
pass
else:
if isunit:
return UnitTestCase(name, parent=collector)
except:
return False
def pytest_pycollect_makeitem(collector, name, obj):
if is_unittest(obj):
return UnitTestCase(name, parent=collector)
class UnitTestCase(pytest.Class):
nofuncargs = True # marker for fixturemanger.getfixtureinfo()
# to declare that our children do not support funcargs
#
def setup(self):
cls = self.obj
if getattr(cls, '__unittest_skip__', False):
return # skipped
setup = getattr(cls, 'setUpClass', None)
if setup is not None:
setup()
teardown = getattr(cls, 'tearDownClass', None)
if teardown is not None:
self.addfinalizer(teardown)
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
cls = self.obj
foundsomething = False
for name in loader.getTestCaseNames(self.obj):
x = getattr(self.obj, name)
funcobj = getattr(x, 'im_func', x)
@@ -31,18 +53,16 @@ class UnitTestCase(pytest.Class):
if hasattr(funcobj, 'todo'):
pytest.mark.xfail(reason=str(funcobj.todo))(funcobj)
yield TestCaseFunction(name, parent=self)
foundsomething = True
if not foundsomething:
runtest = getattr(self.obj, 'runTest', None)
if runtest is not None:
ut = sys.modules.get("twisted.trial.unittest", None)
if ut is None or runtest != ut.TestCase.runTest:
yield TestCaseFunction('runTest', parent=self)
def setup(self):
meth = getattr(self.obj, 'setUpClass', None)
if meth is not None:
meth()
super(UnitTestCase, self).setup()
def teardown(self):
meth = getattr(self.obj, 'tearDownClass', None)
if meth is not None:
meth()
super(UnitTestCase, self).teardown()
class TestCaseFunction(pytest.Function):
_excinfo = None
@@ -56,6 +76,8 @@ class TestCaseFunction(pytest.Function):
pytest.skip(self._obj.skip)
if hasattr(self._testcase, 'setup_method'):
self._testcase.setup_method(self._obj)
if hasattr(self, "_request"):
self._request._fillfixtures()
def teardown(self):
if hasattr(self._testcase, 'teardown_method'):
@@ -91,22 +113,28 @@ class TestCaseFunction(pytest.Function):
self._addexcinfo(rawexcinfo)
def addFailure(self, testcase, rawexcinfo):
self._addexcinfo(rawexcinfo)
def addSkip(self, testcase, reason):
try:
pytest.skip(reason)
except pytest.skip.Exception:
self._addexcinfo(sys.exc_info())
def addExpectedFailure(self, testcase, rawexcinfo, reason):
def addExpectedFailure(self, testcase, rawexcinfo, reason=""):
try:
pytest.xfail(str(reason))
except pytest.xfail.Exception:
self._addexcinfo(sys.exc_info())
def addUnexpectedSuccess(self, testcase, reason):
pass
def addUnexpectedSuccess(self, testcase, reason=""):
self._unexpectedsuccess = reason
def addSuccess(self, testcase):
pass
def stopTest(self, testcase):
pass
def runtest(self):
self._testcase(result=self)
@@ -122,7 +150,10 @@ def pytest_runtest_makereport(item, call):
if isinstance(item, TestCaseFunction):
if item._excinfo:
call.excinfo = item._excinfo.pop(0)
del call.result
try:
del call.result
except AttributeError:
pass
# twisted trial support
def pytest_runtest_protocol(item, __multicall__):

View File

@@ -7,4 +7,4 @@ if __name__ == '__main__':
p = pstats.Stats("prof")
p.strip_dirs()
p.sort_stats('cumulative')
print(p.print_stats(30))
print(p.print_stats(50))

View File

@@ -0,0 +1,19 @@
# 10000 iterations, just for relative comparison
# 2.7.5 3.3.2
# FilesCompleter 75.1109 69.2116
# FastFilesCompleter 0.7383 1.0760
if __name__ == '__main__':
import sys
import timeit
from argcomplete.completers import FilesCompleter
from _pytest._argcomplete import FastFilesCompleter
count = 1000 # only a few seconds
setup = 'from __main__ import FastFilesCompleter\nfc = FastFilesCompleter()'
run = 'fc("/d")'
sys.stdout.write('%s\n' % (timeit.timeit(run,
setup=setup.replace('Fast', ''), number=count)))
sys.stdout.write('%s\n' % (timeit.timeit(run, setup=setup, number=count)))

View File

@@ -1,485 +0,0 @@
#!python
"""Bootstrap distribute installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setup.py::
from distribute_setup import use_setuptools
use_setuptools()
If you want to require a specific version of setuptools, set a download
mirror, or use an alternate download directory, you can do so by supplying
the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
import os
import sys
import time
import fnmatch
import tempfile
import tarfile
from distutils import log
try:
from site import USER_SITE
except ImportError:
USER_SITE = None
try:
import subprocess
def _python_cmd(*args):
args = (sys.executable,) + args
return subprocess.call(args) == 0
except ImportError:
# will be used for python 2.3
def _python_cmd(*args):
args = (sys.executable,) + args
# quoting arguments if windows
if sys.platform == 'win32':
def quote(arg):
if ' ' in arg:
return '"%s"' % arg
return arg
args = [quote(arg) for arg in args]
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
DEFAULT_VERSION = "0.6.24"
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
SETUPTOOLS_FAKED_VERSION = "0.6c11"
SETUPTOOLS_PKG_INFO = """\
Metadata-Version: 1.0
Name: setuptools
Version: %s
Summary: xxxx
Home-page: xxx
Author: xxx
Author-email: xxx
License: xxx
Description: xxx
""" % SETUPTOOLS_FAKED_VERSION
def _install(tarball):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# installing
log.warn('Installing Distribute')
if not _python_cmd('setup.py', 'install'):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
finally:
os.chdir(old_wd)
def _build_egg(egg, tarball, to_dir):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# building an egg
log.warn('Building a Distribute egg in %s', to_dir)
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
finally:
os.chdir(old_wd)
# returning the result
log.warn(egg)
if not os.path.exists(egg):
raise IOError('Could not build the egg.')
def _do_download(version, download_base, to_dir, download_delay):
egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg'
% (version, sys.version_info[0], sys.version_info[1]))
if not os.path.exists(egg):
tarball = download_setuptools(version, download_base,
to_dir, download_delay)
_build_egg(egg, tarball, to_dir)
sys.path.insert(0, egg)
import setuptools
setuptools.bootstrap_install_from = egg
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15, no_fake=True):
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
was_imported = 'pkg_resources' in sys.modules or \
'setuptools' in sys.modules
try:
try:
import pkg_resources
if not hasattr(pkg_resources, '_distribute'):
if not no_fake:
_fake_setuptools()
raise ImportError
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("distribute>="+version)
return
except pkg_resources.VersionConflict:
e = sys.exc_info()[1]
if was_imported:
sys.stderr.write(
"The required version of distribute (>=%s) is not available,\n"
"and can't be installed while this script is running. Please\n"
"install a more recent version first, using\n"
"'easy_install -U distribute'."
"\n\n(Currently using %r)\n" % (version, e.args[0]))
sys.exit(2)
else:
del pkg_resources, sys.modules['pkg_resources'] # reload ok
return _do_download(version, download_base, to_dir,
download_delay)
except pkg_resources.DistributionNotFound:
return _do_download(version, download_base, to_dir,
download_delay)
finally:
if not no_fake:
_create_fake_setuptools_pkg_info(to_dir)
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15):
"""Download distribute from a specified location and return its filename
`version` should be a valid distribute version number that is available
as an egg for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download
attempt.
"""
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
tgz_name = "distribute-%s.tar.gz" % version
url = download_base + tgz_name
saveto = os.path.join(to_dir, tgz_name)
src = dst = None
if not os.path.exists(saveto): # Avoid repeated downloads
try:
log.warn("Downloading %s", url)
src = urlopen(url)
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data = src.read()
dst = open(saveto, "wb")
dst.write(data)
finally:
if src:
src.close()
if dst:
dst.close()
return os.path.realpath(saveto)
def _no_sandbox(function):
def __no_sandbox(*args, **kw):
try:
from setuptools.sandbox import DirectorySandbox
if not hasattr(DirectorySandbox, '_old'):
def violation(*args):
pass
DirectorySandbox._old = DirectorySandbox._violation
DirectorySandbox._violation = violation
patched = True
else:
patched = False
except ImportError:
patched = False
try:
return function(*args, **kw)
finally:
if patched:
DirectorySandbox._violation = DirectorySandbox._old
del DirectorySandbox._old
return __no_sandbox
def _patch_file(path, content):
"""Will backup the file then patch it"""
existing_content = open(path).read()
if existing_content == content:
# already patched
log.warn('Already patched.')
return False
log.warn('Patching...')
_rename_path(path)
f = open(path, 'w')
try:
f.write(content)
finally:
f.close()
return True
_patch_file = _no_sandbox(_patch_file)
def _same_content(path, content):
return open(path).read() == content
def _rename_path(path):
new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name)
os.rename(path, new_name)
return new_name
def _remove_flat_installation(placeholder):
if not os.path.isdir(placeholder):
log.warn('Unkown installation at %s', placeholder)
return False
found = False
for file in os.listdir(placeholder):
if fnmatch.fnmatch(file, 'setuptools*.egg-info'):
found = True
break
if not found:
log.warn('Could not locate setuptools*.egg-info')
return
log.warn('Removing elements out of the way...')
pkg_info = os.path.join(placeholder, file)
if os.path.isdir(pkg_info):
patched = _patch_egg_dir(pkg_info)
else:
patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO)
if not patched:
log.warn('%s already patched.', pkg_info)
return False
# now let's move the files out of the way
for element in ('setuptools', 'pkg_resources.py', 'site.py'):
element = os.path.join(placeholder, element)
if os.path.exists(element):
_rename_path(element)
else:
log.warn('Could not find the %s element of the '
'Setuptools distribution', element)
return True
_remove_flat_installation = _no_sandbox(_remove_flat_installation)
def _after_install(dist):
log.warn('After install bootstrap.')
placeholder = dist.get_command_obj('install').install_purelib
_create_fake_setuptools_pkg_info(placeholder)
def _create_fake_setuptools_pkg_info(placeholder):
if not placeholder or not os.path.exists(placeholder):
log.warn('Could not find the install location')
return
pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
setuptools_file = 'setuptools-%s-py%s.egg-info' % \
(SETUPTOOLS_FAKED_VERSION, pyver)
pkg_info = os.path.join(placeholder, setuptools_file)
if os.path.exists(pkg_info):
log.warn('%s already exists', pkg_info)
return
log.warn('Creating %s', pkg_info)
f = open(pkg_info, 'w')
try:
f.write(SETUPTOOLS_PKG_INFO)
finally:
f.close()
pth_file = os.path.join(placeholder, 'setuptools.pth')
log.warn('Creating %s', pth_file)
f = open(pth_file, 'w')
try:
f.write(os.path.join(os.curdir, setuptools_file))
finally:
f.close()
_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info)
def _patch_egg_dir(path):
# let's check if it's already patched
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
if os.path.exists(pkg_info):
if _same_content(pkg_info, SETUPTOOLS_PKG_INFO):
log.warn('%s already patched.', pkg_info)
return False
_rename_path(path)
os.mkdir(path)
os.mkdir(os.path.join(path, 'EGG-INFO'))
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
f = open(pkg_info, 'w')
try:
f.write(SETUPTOOLS_PKG_INFO)
finally:
f.close()
return True
_patch_egg_dir = _no_sandbox(_patch_egg_dir)
def _before_install():
log.warn('Before install bootstrap.')
_fake_setuptools()
def _under_prefix(location):
if 'install' not in sys.argv:
return True
args = sys.argv[sys.argv.index('install')+1:]
for index, arg in enumerate(args):
for option in ('--root', '--prefix'):
if arg.startswith('%s=' % option):
top_dir = arg.split('root=')[-1]
return location.startswith(top_dir)
elif arg == option:
if len(args) > index:
top_dir = args[index+1]
return location.startswith(top_dir)
if arg == '--user' and USER_SITE is not None:
return location.startswith(USER_SITE)
return True
def _fake_setuptools():
log.warn('Scanning installed packages')
try:
import pkg_resources
except ImportError:
# we're cool
log.warn('Setuptools or Distribute does not seem to be installed.')
return
ws = pkg_resources.working_set
try:
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
replacement=False))
except TypeError:
# old distribute API
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
if setuptools_dist is None:
log.warn('No setuptools distribution found')
return
# detecting if it was already faked
setuptools_location = setuptools_dist.location
log.warn('Setuptools installation detected at %s', setuptools_location)
# if --root or --preix was provided, and if
# setuptools is not located in them, we don't patch it
if not _under_prefix(setuptools_location):
log.warn('Not patching, --root or --prefix is installing Distribute'
' in another location')
return
# let's see if its an egg
if not setuptools_location.endswith('.egg'):
log.warn('Non-egg installation')
res = _remove_flat_installation(setuptools_location)
if not res:
return
else:
log.warn('Egg installation')
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
if (os.path.exists(pkg_info) and
_same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
log.warn('Already patched.')
return
log.warn('Patching...')
# let's create a fake egg replacing setuptools one
res = _patch_egg_dir(setuptools_location)
if not res:
return
log.warn('Patched done.')
_relaunch()
def _relaunch():
log.warn('Relaunching...')
# we have to relaunch the process
# pip marker to avoid a relaunch bug
if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']:
sys.argv[0] = 'setup.py'
args = [sys.executable] + sys.argv
sys.exit(subprocess.call(args))
def _extractall(self, path=".", members=None):
"""Extract all members from the archive to the current working
directory and set owner, modification time and permissions on
directories afterwards. `path' specifies a different directory
to extract to. `members' is optional and must be a subset of the
list returned by getmembers().
"""
import copy
import operator
from tarfile import ExtractError
directories = []
if members is None:
members = self
for tarinfo in members:
if tarinfo.isdir():
# Extract directories with a safe mode.
directories.append(tarinfo)
tarinfo = copy.copy(tarinfo)
tarinfo.mode = 448 # decimal for oct 0700
self.extract(tarinfo, path)
# Reverse sort directories.
if sys.version_info < (2, 4):
def sorter(dir1, dir2):
return cmp(dir1.name, dir2.name)
directories.sort(sorter)
directories.reverse()
else:
directories.sort(key=operator.attrgetter('name'), reverse=True)
# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
dirpath = os.path.join(path, tarinfo.name)
try:
self.chown(tarinfo, dirpath)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
except ExtractError:
e = sys.exc_info()[1]
if self.errorlevel > 1:
raise
else:
self._dbg(1, "tarfile: %s" % e)
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
tarball = download_setuptools()
_install(tarball)
if __name__ == '__main__':
main(sys.argv[1:])

View File

@@ -1,43 +0,0 @@
.. _`contact channels`:
.. _`contact`:
Contact channels
===================================
- `new issue tracker`_ to report bugs or suggest features (for version
2.0 and above). You may also peek at the `old issue tracker`_ but please
don't submit bugs there anymore.
- `Testing In Python`_: a mailing list for Python testing tools and discussion.
- `py-dev developers list`_ pytest specific announcements and discussions.
- #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
- `commit mailing list`_
- `merlinux.eu`_ offers on-site teaching and consulting services.
.. _`new issue tracker`: http://bitbucket.org/hpk42/pytest/issues/
.. _`old issue tracker`: http://bitbucket.org/hpk42/py-trunk/issues/
.. _`merlinux.eu`: http://merlinux.eu
.. _`get an account`:
.. _tetamap: http://tetamap.wordpress.com
.. _`@pylibcommit`: http://twitter.com/pylibcommit
.. _`Testing in Python`: http://lists.idyll.org/listinfo/testing-in-python
.. _FOAF: http://en.wikipedia.org/wiki/FOAF
.. _`py-dev`:
.. _`development mailing list`:
.. _`py-dev developers list`: http://codespeak.net/mailman/listinfo/py-dev
.. _`py-svn`:
.. _`commit mailing list`: http://codespeak.net/mailman/listinfo/py-svn

161
doc/en/Makefile Normal file
View File

@@ -0,0 +1,161 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
SITETARGET=latest
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
regen:
PYTHONDONTWRITEBYTECODE=1 COLUMNS=76 regendoc --update *.txt */*.txt
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
install: html
rsync -avz _build/html/ pytest.org:/www/pytest.org/$(SITETARGET)
installpdf: latexpdf
@scp $(BUILDDIR)/latex/pytest.pdf pytest.org:/www/pytest.org/$(SITETARGET)
installall: clean install installpdf
@echo "done"
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pytest.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pytest.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/pytest"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pytest"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
make -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
texinfo:
mkdir -p $(BUILDDIR)/texinfo
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
mkdir -p $(BUILDDIR)/texinfo
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."

View File

@@ -3,6 +3,9 @@
{% block relbaritems %}
{{ super() }}
<g:plusone></g:plusone>
{% endblock %}
{% block footer %}

View File

@@ -31,6 +31,8 @@
<a href="https://bitbucket.org/hpk42/pytest/issues?status=new&status=open">issues[bb]</a>
</td><td>
<a href="{{ pathto('contact') }}">contact</a>
</td></tr><tr><td>
<a href="{{ pathto('talks') }}">Talks/Posts</a>
</td></tr></table>
</div>
{% extends "basic/localtoc.html" %}

View File

@@ -5,6 +5,16 @@ Release announcements
.. toctree::
:maxdepth: 2
release-2.4.2
release-2.4.1
release-2.4.0
release-2.3.5
release-2.3.4
release-2.3.3
release-2.3.2
release-2.3.1
release-2.3.0
release-2.2.4
release-2.2.2
release-2.2.1
release-2.2.0

View File

@@ -0,0 +1,67 @@
py.test 2.0.1: bug fixes
===========================================================================
Welcome to pytest-2.0.1, a maintenance and bug fix release of pytest,
a mature testing tool for Python, supporting CPython 2.4-3.2, Jython
and latest PyPy interpreters. See extensive docs with tested examples here:
http://pytest.org/
If you want to install or upgrade pytest, just type one of::
pip install -U pytest # or
easy_install -U pytest
Many thanks to all issue reporters and people asking questions or
complaining. Particular thanks to Floris Bruynooghe and Ronny Pfannschmidt
for their great coding contributions and many others for feedback and help.
best,
holger krekel
Changes between 2.0.0 and 2.0.1
----------------------------------------------
- refine and unify initial capturing so that it works nicely
even if the logging module is used on an early-loaded conftest.py
file or plugin.
- fix issue12 - show plugin versions with "--version" and
"--traceconfig" and also document how to add extra information
to reporting test header
- fix issue17 (import-* reporting issue on python3) by
requiring py>1.4.0 (1.4.1 is going to include it)
- fix issue10 (numpy arrays truth checking) by refining
assertion interpretation in py lib
- fix issue15: make nose compatibility tests compatible
with python3 (now that nose-1.0 supports python3)
- remove somewhat surprising "same-conftest" detection because
it ignores conftest.py when they appear in several subdirs.
- improve assertions ("not in"), thanks Floris Bruynooghe
- improve behaviour/warnings when running on top of "python -OO"
(assertions and docstrings are turned off, leading to potential
false positives)
- introduce a pytest_cmdline_processargs(args) hook
to allow dynamic computation of command line arguments.
This fixes a regression because py.test prior to 2.0
allowed to set command line options from conftest.py
files which so far pytest-2.0 only allowed from ini-files now.
- fix issue7: assert failures in doctest modules.
unexpected failures in doctests will not generally
show nicer, i.e. within the doctest failing context.
- fix issue9: setup/teardown functions for an xfail-marked
test will report as xfail if they fail but report as normally
passing (not xpassing) if they succeed. This only is true
for "direct" setup/teardown invocations because teardown_class/
teardown_module cannot closely relate to a single test.
- fix issue14: no logging errors at process exit
- refinements to "collecting" output on non-ttys
- refine internal plugin registration and --traceconfig output
- introduce a mechanism to prevent/unregister plugins from the
command line, see http://pytest.org/latest/plugins.html#cmdunregister
- activate resultlog plugin by default
- fix regression wrt yielded tests which due to the
collection-before-running semantics were not
setup as with pytest 1.3.4. Note, however, that
the recommended and much cleaner way to do test
parametrization remains the "pytest_generate_tests"
mechanism, see the docs.

View File

@@ -1,9 +1,10 @@
pytest-2.2.2: bug fixes
===========================================================================
pytest-2.2.2 is a minor backward-compatible release of the versatile py.test
testing tool. It contains bug fixes and a few refinements particularly
to reporting with "--collectonly", see below for betails.
pytest-2.2.2 (updated to 2.2.3 to fix packaging issues) is a minor
backward-compatible release of the versatile py.test testing tool. It
contains bug fixes and a few refinements particularly to reporting with
"--collectonly", see below for betails.
For general information see here:

View File

@@ -0,0 +1,39 @@
pytest-2.2.4: bug fixes, better junitxml/unittest/python3 compat
===========================================================================
pytest-2.2.4 is a minor backward-compatible release of the versatile
py.test testing tool. It contains bug fixes and a few refinements
to junitxml reporting, better unittest- and python3 compatibility.
For general information see here:
http://pytest.org/
To install or upgrade pytest:
pip install -U pytest # or
easy_install -U pytest
Special thanks for helping on this release to Ronny Pfannschmidt
and Benjamin Peterson and the contributors of issues.
best,
holger krekel
Changes between 2.2.3 and 2.2.4
-----------------------------------
- fix error message for rewritten assertions involving the % operator
- fix issue 126: correctly match all invalid xml characters for junitxml
binary escape
- fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions
of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called
- fix issue #144: better mangle test ids to junitxml classnames
- upgrade distribute_setup.py to 0.6.27

View File

@@ -0,0 +1,134 @@
pytest-2.3: improved fixtures / better unittest integration
=============================================================================
pytest-2.3 comes with many major improvements for fixture/funcarg management
and parametrized testing in Python. It is now easier, more efficient and
more predicatable to re-run the same tests with different fixture
instances. Also, you can directly declare the caching "scope" of
fixtures so that dependent tests throughout your whole test suite can
re-use database or other expensive fixture objects with ease. Lastly,
it's possible for fixture functions (formerly known as funcarg
factories) to use other fixtures, allowing for a completely modular and
re-useable fixture design.
For detailed info and tutorial-style examples, see:
http://pytest.org/latest/fixture.html
Moreover, there is now support for using pytest fixtures/funcargs with
unittest-style suites, see here for examples:
http://pytest.org/latest/unittest.html
Besides, more unittest-test suites are now expected to "simply work"
with pytest.
All changes are backward compatible and you should be able to continue
to run your test suites and 3rd party plugins that worked with
pytest-2.2.4.
If you are interested in the precise reasoning (including examples) of the
pytest-2.3 fixture evolution, please consult
http://pytest.org/latest/funcarg_compare.html
For general info on installation and getting started:
http://pytest.org/latest/getting-started.html
Docs and PDF access as usual at:
http://pytest.org
and more details for those already in the knowing of pytest can be found
in the CHANGELOG below.
Particular thanks for this release go to Floris Bruynooghe, Alex Okrushko
Carl Meyer, Ronny Pfannschmidt, Benjamin Peterson and Alex Gaynor for helping
to get the new features right and well integrated. Ronny and Floris
also helped to fix a number of bugs and yet more people helped by
providing bug reports.
have fun,
holger krekel
Changes between 2.2.4 and 2.3.0
-----------------------------------
- fix issue202 - better automatic names for parametrized test functions
- fix issue139 - introduce @pytest.fixture which allows direct scoping
and parametrization of funcarg factories. Introduce new @pytest.setup
marker to allow the writing of setup functions which accept funcargs.
- fix issue198 - conftest fixtures were not found on windows32 in some
circumstances with nested directory structures due to path manipulation issues
- fix issue193 skip test functions with were parametrized with empty
parameter sets
- fix python3.3 compat, mostly reporting bits that previously depended
on dict ordering
- introduce re-ordering of tests by resource and parametrization setup
which takes precedence to the usual file-ordering
- fix issue185 monkeypatching time.time does not cause pytest to fail
- fix issue172 duplicate call of pytest.setup-decoratored setup_module
functions
- fix junitxml=path construction so that if tests change the
current working directory and the path is a relative path
it is constructed correctly from the original current working dir.
- fix "python setup.py test" example to cause a proper "errno" return
- fix issue165 - fix broken doc links and mention stackoverflow for FAQ
- catch unicode-issues when writing failure representations
to terminal to prevent the whole session from crashing
- fix xfail/skip confusion: a skip-mark or an imperative pytest.skip
will now take precedence before xfail-markers because we
can't determine xfail/xpass status in case of a skip. see also:
http://stackoverflow.com/questions/11105828/in-py-test-when-i-explicitly-skip-a-test-that-is-marked-as-xfail-how-can-i-get
- always report installed 3rd party plugins in the header of a test run
- fix issue160: a failing setup of an xfail-marked tests should
be reported as xfail (not xpass)
- fix issue128: show captured output when capsys/capfd are used
- fix issue179: propperly show the dependency chain of factories
- pluginmanager.register(...) now raises ValueError if the
plugin has been already registered or the name is taken
- fix issue159: improve http://pytest.org/latest/faq.html
especially with respect to the "magic" history, also mention
pytest-django, trial and unittest integration.
- make request.keywords and node.keywords writable. All descendant
collection nodes will see keyword values. Keywords are dictionaries
containing markers and other info.
- fix issue 178: xml binary escapes are now wrapped in py.xml.raw
- fix issue 176: correctly catch the builtin AssertionError
even when we replaced AssertionError with a subclass on the
python level
- factory discovery no longer fails with magic global callables
that provide no sane __code__ object (mock.call for example)
- fix issue 182: testdir.inprocess_run now considers passed plugins
- fix issue 188: ensure sys.exc_info is clear on python2
before calling into a test
- fix issue 191: add unittest TestCase runTest method support
- fix issue 156: monkeypatch correctly handles class level descriptors
- reporting refinements:
- pytest_report_header now receives a "startdir" so that
you can use startdir.bestrelpath(yourpath) to show
nice relative path
- allow plugins to implement both pytest_report_header and
pytest_sessionstart (sessionstart is invoked first).
- don't show deselected reason line if there is none
- py.test -vv will show all of assert comparisations instead of truncating

View File

@@ -0,0 +1,39 @@
pytest-2.3.1: fix regression with factory functions
===========================================================================
pytest-2.3.1 is a quick follow-up release:
- fix issue202 - regression with fixture functions/funcarg factories:
using "self" is now safe again and works as in 2.2.4. Thanks
to Eduard Schettino for the quick bug report.
- disable pexpect pytest self tests on Freebsd - thanks Koob for the
quick reporting
- fix/improve interactive docs with --markers
See
http://pytest.org/
for general information. To install or upgrade pytest:
pip install -U pytest # or
easy_install -U pytest
best,
holger krekel
Changes between 2.3.0 and 2.3.1
-----------------------------------
- fix issue202 - fix regression: using "self" from fixture functions now
works as expected (it's the same "self" instance that a test method
which uses the fixture sees)
- skip pexpect using tests (test_pdb.py mostly) on freebsd* systems
due to pexpect not supporting it properly (hanging)
- link to web pages from --markers output which provides help for
pytest.mark.* usage.

View File

@@ -0,0 +1,57 @@
pytest-2.3.2: some fixes and more traceback-printing speed
===========================================================================
pytest-2.3.2 is a another stabilization release:
- issue 205: fixes a regression with conftest detection
- issue 208/29: fixes traceback-printing speed in some bad cases
- fix teardown-ordering for parametrized setups
- fix unittest and trial compat behaviour with respect to runTest() methods
- issue 206 and others: some improvements to packaging
- fix issue127 and others: improve some docs
See
http://pytest.org/
for general information. To install or upgrade pytest:
pip install -U pytest # or
easy_install -U pytest
best,
holger krekel
Changes between 2.3.1 and 2.3.2
-----------------------------------
- fix issue208 and fix issue29 use new py version to avoid long pauses
when printing tracebacks in long modules
- fix issue205 - conftests in subdirs customizing
pytest_pycollect_makemodule and pytest_pycollect_makeitem
now work properly
- fix teardown-ordering for parametrized setups
- fix issue127 - better documentation for pytest_addoption
and related objects.
- fix unittest behaviour: TestCase.runtest only called if there are
test methods defined
- improve trial support: don't collect its empty
unittest.TestCase.runTest() method
- "python setup.py test" now works with pytest itself
- fix/improve internal/packaging related bits:
- exception message check of test_nose.py now passes on python33 as well
- issue206 - fix test_assertrewrite.py to work when a global
PYTHONDONTWRITEBYTECODE=1 is present
- add tox.ini to pytest distribution so that ignore-dirs and others config
bits are properly distributed for maintainers who run pytest-own tests

View File

@@ -0,0 +1,62 @@
pytest-2.3.3: integration fixes, py24 suport, ``*/**`` shown in traceback
===========================================================================
pytest-2.3.3 is a another stabilization release of the py.test tool
which offers uebersimple assertions, scalable fixture mechanisms
and deep customization for testing with Python. Particularly,
this release provides:
- integration fixes and improvements related to flask, numpy, nose,
unittest, mock
- makes pytest work on py24 again (yes, people sometimes still need to use it)
- show ``*,**`` args in pytest tracebacks
Thanks to Manuel Jacob, Thomas Waldmann, Ronny Pfannschmidt, Pavel Repin
and Andreas Taumoefolau for providing patches and all for the issues.
See
http://pytest.org/
for general information. To install or upgrade pytest:
pip install -U pytest # or
easy_install -U pytest
best,
holger krekel
Changes between 2.3.2 and 2.3.3
-----------------------------------
- fix issue214 - parse modules that contain special objects like e. g.
flask's request object which blows up on getattr access if no request
is active. thanks Thomas Waldmann.
- fix issue213 - allow to parametrize with values like numpy arrays that
do not support an __eq__ operator
- fix issue215 - split test_python.org into multiple files
- fix issue148 - @unittest.skip on classes is now recognized and avoids
calling setUpClass/tearDownClass, thanks Pavel Repin
- fix issue209 - reintroduce python2.4 support by depending on newer
pylib which re-introduced statement-finding for pre-AST interpreters
- nose support: only call setup if its a callable, thanks Andrew
Taumoefolau
- fix issue219 - add py2.4-3.3 classifiers to TROVE list
- in tracebacks *,** arg values are now shown next to normal arguments
(thanks Manuel Jacob)
- fix issue217 - support mock.patch with pytest's fixtures - note that
you need either mock-1.0.1 or the python3.3 builtin unittest.mock.
- fix issue127 - improve documentation for pytest_addoption() and
add a ``config.getoption(name)`` helper function for consistency.

View File

@@ -0,0 +1,39 @@
pytest-2.3.4: stabilization, more flexible selection via "-k expr"
===========================================================================
pytest-2.3.4 is a small stabilization release of the py.test tool
which offers uebersimple assertions, scalable fixture mechanisms
and deep customization for testing with Python. This release
comes with the following fixes and features:
- make "-k" option accept an expressions the same as with "-m" so that one
can write: -k "name1 or name2" etc. This is a slight usage incompatibility
if you used special syntax like "TestClass.test_method" which you now
need to write as -k "TestClass and test_method" to match a certain
method in a certain test class.
- allow to dynamically define markers via
item.keywords[...]=assignment integrating with "-m" option
- yielded test functions will now have autouse-fixtures active but
cannot accept fixtures as funcargs - it's anyway recommended to
rather use the post-2.0 parametrize features instead of yield, see:
http://pytest.org/latest/example/parametrize.html
- fix autouse-issue where autouse-fixtures would not be discovered
if defined in a a/conftest.py file and tests in a/tests/test_some.py
- fix issue226 - LIFO ordering for fixture teardowns
- fix issue224 - invocations with >256 char arguments now work
- fix issue91 - add/discuss package/directory level setups in example
- fixes related to autouse discovery and calling
Thanks in particular to Thomas Waldmann for spotting and reporting issues.
See
http://pytest.org/
for general information. To install or upgrade pytest:
pip install -U pytest # or
easy_install -U pytest
best,
holger krekel

View File

@@ -0,0 +1,97 @@
pytest-2.3.5: bug fixes and little improvements
===========================================================================
pytest-2.3.5 is a maintenance release with many bug fixes and little
improvements. See the changelog below for details. No backward
compatibility issues are foreseen and all plugins which worked with the
prior version are expected to work unmodified. Speaking of which, a
few interesting new plugins saw the light last month:
- pytest-instafail: show failure information while tests are running
- pytest-qt: testing of GUI applications written with QT/Pyside
- pytest-xprocess: managing external processes across test runs
- pytest-random: randomize test ordering
And several others like pytest-django saw maintenance releases.
For a more complete list, check out
https://pypi.python.org/pypi?%3Aaction=search&term=pytest&submit=search.
For general information see:
http://pytest.org/
To install or upgrade pytest:
pip install -U pytest # or
easy_install -U pytest
Particular thanks to Floris, Ronny, Benjamin and the many bug reporters
and fix providers.
may the fixtures be with you,
holger krekel
Changes between 2.3.4 and 2.3.5
-----------------------------------
- never consider a fixture function for test function collection
- allow re-running of test items / helps to fix pytest-reruntests plugin
and also help to keep less fixture/resource references alive
- put captured stdout/stderr into junitxml output even for passing tests
(thanks Adam Goucher)
- Issue 265 - integrate nose setup/teardown with setupstate
so it doesnt try to teardown if it did not setup
- issue 271 - dont write junitxml on slave nodes
- Issue 274 - dont try to show full doctest example
when doctest does not know the example location
- issue 280 - disable assertion rewriting on buggy CPython 2.6.0
- inject "getfixture()" helper to retrieve fixtures from doctests,
thanks Andreas Zeidler
- issue 259 - when assertion rewriting, be consistent with the default
source encoding of ASCII on Python 2
- issue 251 - report a skip instead of ignoring classes with init
- issue250 unicode/str mixes in parametrization names and values now works
- issue257, assertion-triggered compilation of source ending in a
comment line doesn't blow up in python2.5 (fixed through py>=1.4.13.dev6)
- fix --genscript option to generate standalone scripts that also
work with python3.3 (importer ordering)
- issue171 - in assertion rewriting, show the repr of some
global variables
- fix option help for "-k"
- move long description of distribution into README.rst
- improve docstring for metafunc.parametrize()
- fix bug where using capsys with pytest.set_trace() in a test
function would break when looking at capsys.readouterr()
- allow to specify prefixes starting with "_" when
customizing python_functions test discovery. (thanks Graham Horler)
- improve PYTEST_DEBUG tracing output by puting
extra data on a new lines with additional indent
- ensure OutcomeExceptions like skip/fail have initialized exception attributes
- issue 260 - don't use nose special setup on plain unittest cases
- fix issue134 - print the collect errors that prevent running specified test items
- fix issue266 - accept unicode in MarkEvaluator expressions

View File

@@ -0,0 +1,225 @@
pytest-2.4.0: new fixture features/hooks and bug fixes
===========================================================================
The just released pytest-2.4.0 brings many improvements and numerous
bug fixes while remaining plugin- and test-suite compatible apart
from a few supposedly very minor incompatibilities. See below for
a full list of details. A few feature highlights:
- new yield-style fixtures `pytest.yield_fixture
<http://pytest.org/latest/yieldfixture.html>`_, allowing to use
existing with-style context managers in fixture functions.
- improved pdb support: ``import pdb ; pdb.set_trace()`` now works
without requiring prior disabling of stdout/stderr capturing.
Also the ``--pdb`` options works now on collection and internal errors
and we introduced a new experimental hook for IDEs/plugins to
intercept debugging: ``pytest_exception_interact(node, call, report)``.
- shorter monkeypatch variant to allow specifying an import path as
a target, for example: ``monkeypatch.setattr("requests.get", myfunc)``
- better unittest/nose compatibility: all teardown methods are now only
called if the corresponding setup method succeeded.
- integrate tab-completion on command line options if you
have `argcomplete <http://pypi.python.org/pypi/argcomplete>`_
configured.
- allow boolean expression directly with skipif/xfail
if a "reason" is also specified.
- a new hook ``pytest_load_initial_conftests`` allows plugins like
`pytest-django <http://pypi.python.org/pypi/pytest-django>`_ to
influence the environment before conftest files import ``django``.
- reporting: color the last line red or green depending if
failures/errors occured or everything passed.
The documentation has been updated to accomodate the changes,
see `http://pytest.org <http://pytest.org>`_
To install or upgrade pytest::
pip install -U pytest # or
easy_install -U pytest
**Many thanks to all who helped, including Floris Bruynooghe,
Brianna Laugher, Andreas Pelme, Anthon van der Neut, Anatoly Bubenkoff,
Vladimir Keleshev, Mathieu Agopian, Ronny Pfannschmidt, Christian
Theunert and many others.**
may passing tests be with you,
holger krekel
Changes between 2.3.5 and 2.4
-----------------------------------
known incompatibilities:
- if calling --genscript from python2.7 or above, you only get a
standalone script which works on python2.7 or above. Use Python2.6
to also get a python2.5 compatible version.
- all xunit-style teardown methods (nose-style, pytest-style,
unittest-style) will not be called if the corresponding setup method failed,
see issue322 below.
- the pytest_plugin_unregister hook wasn't ever properly called
and there is no known implementation of the hook - so it got removed.
- pytest.fixture-decorated functions cannot be generators (i.e. use
yield) anymore. This change might be reversed in 2.4.1 if it causes
unforeseen real-life issues. However, you can always write and return
an inner function/generator and change the fixture consumer to iterate
over the returned generator. This change was done in lieu of the new
``pytest.yield_fixture`` decorator, see below.
new features:
- experimentally introduce a new ``pytest.yield_fixture`` decorator
which accepts exactly the same parameters as pytest.fixture but
mandates a ``yield`` statement instead of a ``return statement`` from
fixture functions. This allows direct integration with "with-style"
context managers in fixture functions and generally avoids registering
of finalization callbacks in favour of treating the "after-yield" as
teardown code. Thanks Andreas Pelme, Vladimir Keleshev, Floris
Bruynooghe, Ronny Pfannschmidt and many others for discussions.
- allow boolean expression directly with skipif/xfail
if a "reason" is also specified. Rework skipping documentation
to recommend "condition as booleans" because it prevents surprises
when importing markers between modules. Specifying conditions
as strings will remain fully supported.
- reporting: color the last line red or green depending if
failures/errors occured or everything passed. thanks Christian
Theunert.
- make "import pdb ; pdb.set_trace()" work natively wrt capturing (no
"-s" needed anymore), making ``pytest.set_trace()`` a mere shortcut.
- fix issue181: --pdb now also works on collect errors (and
on internal errors) . This was implemented by a slight internal
refactoring and the introduction of a new hook
``pytest_exception_interact`` hook (see next item).
- fix issue341: introduce new experimental hook for IDEs/terminals to
intercept debugging: ``pytest_exception_interact(node, call, report)``.
- new monkeypatch.setattr() variant to provide a shorter
invocation for patching out classes/functions from modules:
monkeypatch.setattr("requests.get", myfunc)
will replace the "get" function of the "requests" module with ``myfunc``.
- fix issue322: tearDownClass is not run if setUpClass failed. Thanks
Mathieu Agopian for the initial fix. Also make all of pytest/nose
finalizer mimick the same generic behaviour: if a setupX exists and
fails, don't run teardownX. This internally introduces a new method
"node.addfinalizer()" helper which can only be called during the setup
phase of a node.
- simplify pytest.mark.parametrize() signature: allow to pass a
CSV-separated string to specify argnames. For example:
``pytest.mark.parametrize("input,expected", [(1,2), (2,3)])``
works as well as the previous:
``pytest.mark.parametrize(("input", "expected"), ...)``.
- add support for setUpModule/tearDownModule detection, thanks Brian Okken.
- integrate tab-completion on options through use of "argcomplete".
Thanks Anthon van der Neut for the PR.
- change option names to be hyphen-separated long options but keep the
old spelling backward compatible. py.test -h will only show the
hyphenated version, for example "--collect-only" but "--collectonly"
will remain valid as well (for backward-compat reasons). Many thanks to
Anthon van der Neut for the implementation and to Hynek Schlawack for
pushing us.
- fix issue 308 - allow to mark/xfail/skip individual parameter sets
when parametrizing. Thanks Brianna Laugher.
- call new experimental pytest_load_initial_conftests hook to allow
3rd party plugins to do something before a conftest is loaded.
Bug fixes:
- fix issue358 - capturing options are now parsed more properly
by using a new parser.parse_known_args method.
- pytest now uses argparse instead of optparse (thanks Anthon) which
means that "argparse" is added as a dependency if installing into python2.6
environments or below.
- fix issue333: fix a case of bad unittest/pytest hook interaction.
- PR27: correctly handle nose.SkipTest during collection. Thanks
Antonio Cuni, Ronny Pfannschmidt.
- fix issue355: junitxml puts name="pytest" attribute to testsuite tag.
- fix issue336: autouse fixture in plugins should work again.
- fix issue279: improve object comparisons on assertion failure
for standard datatypes and recognise collections.abc. Thanks to
Brianna Laugher and Mathieu Agopian.
- fix issue317: assertion rewriter support for the is_package method
- fix issue335: document py.code.ExceptionInfo() object returned
from pytest.raises(), thanks Mathieu Agopian.
- remove implicit distribute_setup support from setup.py.
- fix issue305: ignore any problems when writing pyc files.
- SO-17664702: call fixture finalizers even if the fixture function
partially failed (finalizers would not always be called before)
- fix issue320 - fix class scope for fixtures when mixed with
module-level functions. Thanks Anatloy Bubenkoff.
- you can specify "-q" or "-qq" to get different levels of "quieter"
reporting (thanks Katarzyna Jachim)
- fix issue300 - Fix order of conftest loading when starting py.test
in a subdirectory.
- fix issue323 - sorting of many module-scoped arg parametrizations
- make sessionfinish hooks execute with the same cwd-context as at
session start (helps fix plugin behaviour which write output files
with relative path such as pytest-cov)
- fix issue316 - properly reference collection hooks in docs
- fix issue 306 - cleanup of -k/-m options to only match markers/test
names/keywords respectively. Thanks Wouter van Ackooy.
- improved doctest counting for doctests in python modules --
files without any doctest items will not show up anymore
and doctest examples are counted as separate test items.
thanks Danilo Bellini.
- fix issue245 by depending on the released py-1.4.14
which fixes py.io.dupfile to work with files with no
mode. Thanks Jason R. Coombs.
- fix junitxml generation when test output contains control characters,
addressing issue267, thanks Jaap Broekhuizen
- fix issue338: honor --tb style for setup/teardown errors as well. Thanks Maho.
- fix issue307 - use yaml.safe_load in example, thanks Mark Eichin.
- better parametrize error messages, thanks Brianna Laugher
- pytest_terminal_summary(terminalreporter) hooks can now use
".section(title)" and ".line(msg)" methods to print extra
information at the end of a test run.

View File

@@ -0,0 +1,25 @@
pytest-2.4.1: fixing three regressions compared to 2.3.5
===========================================================================
pytest-2.4.1 is a quick follow up release to fix three regressions
compared to 2.3.5 before they hit more people:
- When using parser.addoption() unicode arguments to the
"type" keyword should also be converted to the respective types.
thanks Floris Bruynooghe, @dnozay. (fixes issue360 and issue362)
- fix dotted filename completion when using argcomplete
thanks Anthon van der Neuth. (fixes issue361)
- fix regression when a 1-tuple ("arg",) is used for specifying
parametrization (the values of the parametrization were passed
nested in a tuple). Thanks Donald Stufft.
- also merge doc typo fixes, thanks Andy Dirnberger
as usual, docs at http://pytest.org and upgrades via::
pip install -U pytest
have fun,
holger krekel

View File

@@ -0,0 +1,39 @@
pytest-2.4.2: colorama on windows, plugin/tmpdir fixes
===========================================================================
pytest-2.4.2 is another bug-fixing release:
- on Windows require colorama and a newer py lib so that py.io.TerminalWriter()
now uses colorama instead of its own ctypes hacks. (fixes issue365)
thanks Paul Moore for bringing it up.
- fix "-k" matching of tests where "repr" and "attr" and other names would
cause wrong matches because of an internal implementation quirk
(don't ask) which is now properly implemented. fixes issue345.
- avoid tmpdir fixture to create too long filenames especially
when parametrization is used (issue354)
- fix pytest-pep8 and pytest-flakes / pytest interactions
(collection names in mark plugin was assuming an item always
has a function which is not true for those plugins etc.)
Thanks Andi Zeidler.
- introduce node.get_marker/node.add_marker API for plugins
like pytest-pep8 and pytest-flakes to avoid the messy
details of the node.keywords pseudo-dicts. Adapated
docs.
- remove attempt to "dup" stdout at startup as it's icky.
the normal capturing should catch enough possibilities
of tests messing up standard FDs.
- add pluginmanager.do_configure(config) as a link to
config.do_configure() for plugin-compatibility
as usual, docs at http://pytest.org and upgrades via::
pip install -U pytest
have fun,
holger krekel

View File

@@ -10,14 +10,16 @@ py.test reference documentation
builtin.txt
customize.txt
assert.txt
funcargs.txt
fixture.txt
yieldfixture.txt
parametrize.txt
xunit_setup.txt
capture.txt
monkeypatch.txt
xdist.txt
tmpdir.txt
skipping.txt
mark.txt
skipping.txt
recwarn.txt
unittest.txt
nose.txt

View File

@@ -2,7 +2,10 @@
The writing and reporting of assertions in tests
==================================================
.. _`assertfeedback`:
.. _`assert with the assert statement`:
.. _`assert`:
Asserting with the ``assert`` statement
---------------------------------------------------------
@@ -23,8 +26,8 @@ you will see the return value of the function call::
$ py.test test_assert1.py
=========================== test session starts ============================
platform darwin -- Python 2.7.1 -- pytest-2.2.2
collecting ... collected 1 items
platform linux2 -- Python 2.7.3 -- pytest-2.4.2
collected 1 items
test_assert1.py F
@@ -37,7 +40,7 @@ you will see the return value of the function call::
E + where 3 = f()
test_assert1.py:5: AssertionError
========================= 1 failed in 0.02 seconds =========================
========================= 1 failed in 0.01 seconds =========================
py.test has support for showing the values of the most common subexpressions
including calls, attributes, comparisons, and binary and unary
@@ -54,6 +57,8 @@ will be simply shown in the traceback.
See :ref:`assert-details` for more information on assertion introspection.
.. _`assertraises`:
Assertions about expected exceptions
------------------------------------------
@@ -73,6 +78,12 @@ and if you need to have access to the actual exception info you may use::
# do checks related to excinfo.type, excinfo.value, excinfo.traceback
``excinfo`` is a `py.code.ExceptionInfo`_ instance, which is a wrapper around
the actual exception raised.
.. _py.code.ExceptionInfo:
http://pylib.readthedocs.org/en/latest/code.html#py-code-exceptioninfo
If you want to write test code that works on Python 2.4 as well,
you may also use two other ways to test for an expected exception::
@@ -105,8 +116,8 @@ if you run this module::
$ py.test test_assert2.py
=========================== test session starts ============================
platform darwin -- Python 2.7.1 -- pytest-2.2.2
collecting ... collected 1 items
platform linux2 -- Python 2.7.3 -- pytest-2.4.2
collected 1 items
test_assert2.py F
@@ -124,7 +135,7 @@ if you run this module::
E '5'
test_assert2.py:5: AssertionError
========================= 1 failed in 0.03 seconds =========================
========================= 1 failed in 0.01 seconds =========================
Special comparisons are done for a number of cases:
@@ -168,7 +179,6 @@ you can run the test module and get the custom output defined in
the conftest file::
$ py.test -q test_foocompare.py
collecting ... collected 1 items
F
================================= FAILURES =================================
_______________________________ test_compare _______________________________
@@ -181,7 +191,7 @@ the conftest file::
E vals: 1 != 2
test_foocompare.py:8: AssertionError
1 failed in 0.02 seconds
1 failed in 0.01 seconds
.. _assert-details:
.. _`assert introspection`:

188
doc/en/attic_fixtures.txt Normal file
View File

@@ -0,0 +1,188 @@
**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

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

View File

@@ -1,37 +1,78 @@
.. _`pytest helpers`:
Pytest builtin helpers
Pytest API and builtin fixtures
================================================
builtin pytest.* functions and helping objects
-----------------------------------------------------
This is a list of ``pytest.*`` API functions and fixtures.
You can always use an interactive Python prompt and type::
For information on plugin hooks and objects, see :ref:`plugins`.
For information on the ``pytest.mark`` mechanism, see :ref:`mark`.
For the below objects, you can also interactively ask for help, e.g. by
typing on the Python interactive prompt something like::
import pytest
help(pytest)
to get an overview on the globally available helpers.
.. currentmodule:: pytest
.. automodule:: pytest
Invoking pytest interactively
---------------------------------------------------
.. autofunction:: main
More examples at :ref:`pytest.main-usage`
Helpers for assertions about Exceptions/Warnings
--------------------------------------------------------
.. autofunction:: raises
Examples at :ref:`assertraises`.
.. autofunction:: deprecated_call
Raising a specific test outcome
--------------------------------------
You can use the following functions in your test, fixture or setup
functions to force a certain test outcome. Note that most often
you can rather use declarative marks, see :ref:`skipping`.
.. autofunction:: _pytest.runner.fail
.. autofunction:: _pytest.runner.skip
.. autofunction:: _pytest.runner.importorskip
.. autofunction:: _pytest.skipping.xfail
.. autofunction:: _pytest.runner.exit
fixtures and requests
-----------------------------------------------------
To mark a fixture function:
.. autofunction:: _pytest.python.fixture
Tutorial at :ref:`fixtures`.
The ``request`` object that can be used from fixture functions.
.. autoclass:: _pytest.python.FixtureRequest()
:members:
.. _builtinfixtures:
.. _builtinfuncargs:
Builtin function arguments
-----------------------------------------------------
Builtin fixtures/function arguments
-----------------------------------------
You can ask for available builtin or project-custom
:ref:`function arguments <funcargs>` by typing::
:ref:`fixtures <fixtures>` by typing::
$ py.test --funcargs
=========================== test session starts ============================
platform darwin -- Python 2.7.1 -- pytest-2.2.2
collected 0 items
pytestconfig
the pytest config object with access to command line opts.
$ py.test -q --fixtures
capsys
enables capturing of writes to sys.stdout/sys.stderr and makes
captured output available via ``capsys.readouterr()`` method calls
@@ -42,13 +83,6 @@ You can ask for available builtin or project-custom
captured output available via ``capsys.readouterr()`` method calls
which return a ``(out, err)`` tuple.
tmpdir
return a temporary directory path object
which is unique to each test function invocation,
created as a sub directory of the base temporary
directory. The returned object is a `py.path.local`_
path object.
monkeypatch
The returned ``monkeypatch`` funcarg provides these
helper methods to modify objects, dictionaries or os.environ::
@@ -67,6 +101,8 @@ You can ask for available builtin or project-custom
parameter determines if a KeyError or AttributeError
will be raised if the set/deletion operation has no target.
pytestconfig
the pytest config object with access to command line opts.
recwarn
Return a WarningsRecorder instance that provides these methods:
@@ -76,7 +112,12 @@ You can ask for available builtin or project-custom
See http://docs.python.org/library/warnings.html for information
on warning categories.
cov
A pytest funcarg that provides access to the underlying coverage object.
tmpdir
return a temporary directory path object
which is unique to each test function invocation,
created as a sub directory of the base temporary
directory. The returned object is a `py.path.local`_
path object.
============================= in 0.01 seconds =============================
in 0.00 seconds

View File

@@ -64,8 +64,8 @@ of the failing function and hide the other one::
$ py.test
=========================== test session starts ============================
platform darwin -- Python 2.7.1 -- pytest-2.2.2
collecting ... collected 2 items
platform linux2 -- Python 2.7.3 -- pytest-2.4.2
collected 2 items
test_module.py .F
@@ -78,8 +78,8 @@ of the failing function and hide the other one::
test_module.py:9: AssertionError
----------------------------- Captured stdout ------------------------------
setting up <function test_func2 at 0x1013230c8>
==================== 1 failed, 1 passed in 0.03 seconds ====================
setting up <function test_func2 at 0x282d2a8>
==================== 1 failed, 1 passed in 0.01 seconds ====================
Accessing captured output from a test function
---------------------------------------------------

View File

@@ -4,4 +4,4 @@
Changelog history
=================================
.. include:: ../CHANGELOG
.. include:: ../../CHANGELOG

301
doc/en/conf.py Normal file
View File

@@ -0,0 +1,301 @@
# -*- coding: utf-8 -*-
#
# pytest documentation build configuration file, created by
# sphinx-quickstart on Fri Oct 8 17:54:28 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The full version, including alpha/beta/rc tags.
# The short X.Y version.
version = "2.4.2"
release = "2.4.2"
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
autodoc_member_order = "bysource"
todo_include_todos = 1
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.autosummary',
'sphinx.ext.intersphinx', 'sphinx.ext.viewcode']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.txt'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'contents'
# General information about the project.
project = u'pytest'
copyright = u'2012, holger krekel'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['links.inc', '_build', 'naming20.txt', 'test/*',
"old_*",
'*attic*',
'*/attic*',
'funcargs.txt',
'setup.txt',
'example/remoteinterp.txt',
]
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
add_module_names = False
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinxdoc'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
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
# 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
# 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,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
#html_sidebars = {'index': 'indexsidebar.html'}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
#html_additional_pages = {'index': 'index.html'}
# If false, no module index is generated.
html_domain_indices = True
# If false, no index is generated.
html_use_index = False
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
html_show_sourcelink = False
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'pytestdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (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'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
latex_domain_indices = False
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('usage', 'pytest', u'pytest usage',
[u'holger krekel at merlinux eu'], 1)
]
# -- Options for Epub output ---------------------------------------------------
# Bibliographic Dublin Core info.
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'
# The language of the text. It defaults to the language option
# or en if the language is not set.
#epub_language = ''
# The scheme of the identifier. Typical schemes are ISBN or URL.
#epub_scheme = ''
# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#epub_identifier = ''
# A unique identification for the text.
#epub_uid = ''
# HTML files that should be inserted before the pages created by sphinx.
# The format is a list of tuples containing the path and title.
#epub_pre_files = []
# HTML files shat should be inserted after the pages created by sphinx.
# The format is a list of tuples containing the path and title.
#epub_post_files = []
# A list of files that should not be packed into the epub file.
#epub_exclude_files = []
# The depth of the table of contents in toc.ncx.
#epub_tocdepth = 3
# Allow duplicate toc entries.
#epub_tocdup = True
# -- Options for texinfo output ------------------------------------------------
texinfo_documents = [
(master_doc, 'pytest', 'pytest Documentation',
('Holger Krekel@*Benjamin Peterson@*Ronny Pfannschmidt@*'
'Floris Bruynooghe@*others'),
'pytest',
'simple powerful testing with Pytho',
'Programming',
1),
]
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'python': ('http://docs.python.org/', None),
# 'lib': ("http://docs.python.org/2.7library/", None),
}
def setup(app):
#from sphinx.ext.autodoc import cut_lines
#app.connect('autodoc-process-docstring', cut_lines(4, what=['module']))
app.add_description_unit('confval', 'confval',
objname='configuration value',
indextemplate='pair: %s; configuration value')

48
doc/en/contact.txt Normal file
View File

@@ -0,0 +1,48 @@
.. _`contact channels`:
.. _`contact`:
Contact channels
===================================
- `pytest issue tracker`_ to report bugs or suggest features (for version
2.0 and above).
- `pytest on stackoverflow.com <http://stackoverflow.com/search?q=pytest>`_
to post questions with the tag ``pytest``. New Questions will usually
be seen by pytest users or developers and answered quickly.
- `Testing In Python`_: a mailing list for Python testing tools and discussion.
- `pytest-dev at python.org (mailing list)`_ pytest specific announcements and discussions.
- `pytest-commit at python.org (mailing list)`_: for commits and new issues
- #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
- `merlinux.eu`_ offers pytest and tox-related professional teaching and
consulting.
.. _`pytest issue tracker`: http://bitbucket.org/hpk42/pytest/issues/
.. _`old issue tracker`: http://bitbucket.org/hpk42/py-trunk/issues/
.. _`merlinux.eu`: http://merlinux.eu
.. _`get an account`:
.. _tetamap: http://tetamap.wordpress.com
.. _`@pylibcommit`: http://twitter.com/pylibcommit
.. _`Testing in Python`: http://lists.idyll.org/listinfo/testing-in-python
.. _FOAF: http://en.wikipedia.org/wiki/FOAF
.. _`py-dev`:
.. _`development mailing list`:
.. _`pytest-dev at python.org (mailing list)`: http://mail.python.org/mailman/listinfo/pytest-dev
.. _`py-svn`:
.. _`pytest-commit at python.org (mailing list)`: http://mail.python.org/mailman/listinfo/pytest-commit

View File

@@ -12,11 +12,12 @@ Full pytest documentation
:maxdepth: 2
overview
example/index
apiref
plugins
example/index
talks
develop
funcarg_compare.txt
announce/index
.. toctree::

View File

@@ -12,6 +12,8 @@ configurations files by using the general help option::
This will display command line and configuration file settings
which were registered by installed plugins.
.. _inifiles:
How test configuration is read from configuration INI-files
-------------------------------------------------------------
@@ -23,8 +25,9 @@ It looks for file basenames in this order::
tox.ini
setup.cfg
Searching stops when the first ``[pytest]`` section is found.
There is no merging of configuration values from multiple files. Example::
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::
py.test path/to/testdir
@@ -94,7 +97,7 @@ Builtin configuration file options
[seq] matches any character in seq
[!seq] matches any char not in seq
Default patterns are ``.* _* CVS {args}``. Setting a ``norecursedir``
Default patterns are ``.* _darcs CVS {args}``. Setting a ``norecursedir``
replaces the default. Here is an example of how to avoid
certain directories::

View File

@@ -44,10 +44,15 @@ then you can just invoke ``py.test`` without command line options::
$ py.test
=========================== test session starts ============================
platform darwin -- Python 2.7.1 -- pytest-2.2.2
collecting ... collected 1 items
platform linux2 -- Python 2.7.3 -- pytest-2.4.2
collected 1 items
mymodule.py .
========================= 1 passed in 0.51 seconds =========================
[?1034h
========================= 1 passed in 0.01 seconds =========================
It is possible to use fixtures using the ``getfixture`` helper::
# content of example.rst
>>> tmp = getfixture('tmpdir')
>>> ...

View File

@@ -0,0 +1,213 @@
from py.test import raises
import py
def otherfunc(a,b):
assert a==b
def somefunc(x,y):
otherfunc(x,y)
def otherfunc_multi(a,b):
assert (a ==
b)
def test_generative(param1, param2):
assert param1 * 2 < param2
def pytest_generate_tests(metafunc):
if 'param1' in metafunc.fixturenames:
metafunc.addcall(funcargs=dict(param1=3, param2=6))
class TestFailing(object):
def test_simple(self):
def f():
return 42
def g():
return 43
assert f() == g()
def test_simple_multiline(self):
otherfunc_multi(
42,
6*9)
def test_not(self):
def f():
return 42
assert not f()
class TestSpecialisedExplanations(object):
def test_eq_text(self):
assert 'spam' == 'eggs'
def test_eq_similar_text(self):
assert 'foo 1 bar' == 'foo 2 bar'
def test_eq_multiline_text(self):
assert 'foo\nspam\nbar' == 'foo\neggs\nbar'
def test_eq_long_text(self):
a = '1'*100 + 'a' + '2'*100
b = '1'*100 + 'b' + '2'*100
assert a == b
def test_eq_long_text_multiline(self):
a = '1\n'*100 + 'a' + '2\n'*100
b = '1\n'*100 + 'b' + '2\n'*100
assert a == b
def test_eq_list(self):
assert [0, 1, 2] == [0, 1, 3]
def test_eq_list_long(self):
a = [0]*100 + [1] + [3]*100
b = [0]*100 + [2] + [3]*100
assert a == b
def test_eq_dict(self):
assert {'a': 0, 'b': 1, 'c': 0} == {'a': 0, 'b': 2, 'd': 0}
def test_eq_set(self):
assert set([0, 10, 11, 12]) == set([0, 20, 21])
def test_eq_longer_list(self):
assert [1,2] == [1,2,3]
def test_in_list(self):
assert 1 in [0, 2, 3, 4, 5]
def test_not_in_text_multiline(self):
text = 'some multiline\ntext\nwhich\nincludes foo\nand a\ntail'
assert 'foo' not in text
def test_not_in_text_single(self):
text = 'single foo line'
assert 'foo' not in text
def test_not_in_text_single_long(self):
text = 'head ' * 50 + 'foo ' + 'tail ' * 20
assert 'foo' not in text
def test_not_in_text_single_long_term(self):
text = 'head ' * 50 + 'f'*70 + 'tail ' * 20
assert 'f'*70 not in text
def test_attribute():
class Foo(object):
b = 1
i = Foo()
assert i.b == 2
def test_attribute_instance():
class Foo(object):
b = 1
assert Foo().b == 2
def test_attribute_failure():
class Foo(object):
def _get_b(self):
raise Exception('Failed to get attrib')
b = property(_get_b)
i = Foo()
assert i.b == 2
def test_attribute_multiple():
class Foo(object):
b = 1
class Bar(object):
b = 2
assert Foo().b == Bar().b
def globf(x):
return x+1
class TestRaises:
def test_raises(self):
s = 'qwe'
raises(TypeError, "int(s)")
def test_raises_doesnt(self):
raises(IOError, "int('3')")
def test_raise(self):
raise ValueError("demo error")
def test_tupleerror(self):
a,b = [1]
def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
l = [1,2,3]
print ("l is %r" % l)
a,b = l.pop()
def test_some_error(self):
if namenotexi:
pass
def func1(self):
assert 41 == 42
# thanks to Matthew Scott for this test
def test_dynamic_compile_shows_nicely():
src = 'def foo():\n assert 1 == 0\n'
name = 'abc-123'
module = py.std.imp.new_module(name)
code = py.code.compile(src, name, 'exec')
py.builtin.exec_(code, module.__dict__)
py.std.sys.modules[name] = module
module.foo()
class TestMoreErrors:
def test_complex_error(self):
def f():
return 44
def g():
return 43
somefunc(f(), g())
def test_z1_unpack_error(self):
l = []
a,b = l
def test_z2_type_error(self):
l = 3
a,b = l
def test_startswith(self):
s = "123"
g = "456"
assert s.startswith(g)
def test_startswith_nested(self):
def f():
return "123"
def g():
return "456"
assert f().startswith(g())
def test_global_func(self):
assert isinstance(globf(42), float)
def test_instance(self):
self.x = 6*7
assert self.x != 42
def test_compare(self):
assert globf(10) < 5
def test_try_finally(self):
x = 1
try:
assert x == 0
finally:
x = 0

View File

@@ -13,9 +13,9 @@ example: specifying and selecting acceptance tests
help="run (slow) acceptance tests")
def pytest_funcarg__accept(request):
return AcceptFuncarg(request)
return AcceptFixture(request)
class AcceptFuncarg:
class AcceptFixture:
def __init__(self, request):
if not request.config.option.acceptance:
pytest.skip("specify -A to run acceptance tests")
@@ -39,7 +39,7 @@ and the actual test function example:
If you run this test without specifying a command line option
the test will get skipped with an appropriate message. Otherwise
you can start to add convenience and test support methods
to your AcceptFuncarg and drive running of tools or
to your AcceptFixture and drive running of tools or
applications and provide ways to do assertions about
the output.

View File

@@ -0,0 +1,18 @@
import pytest
@pytest.fixture("session")
def setup(request):
setup = CostlySetup()
request.addfinalizer(setup.finalize)
return setup
class CostlySetup:
def __init__(self):
import time
print ("performing costly setup")
time.sleep(5)
self.timecostly = 1
def finalize(self):
del self.timecostly

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