Merge pull request #2222 from RonnyPfannschmidt/features

merge master into features
This commit is contained in:
Ronny Pfannschmidt 2017-01-26 13:48:10 +01:00 committed by GitHub
commit 3b47cb45e6
59 changed files with 366 additions and 260 deletions

View File

@ -29,13 +29,11 @@ env:
- TESTENV=docs - TESTENV=docs
matrix: matrix:
allow_failures:
# see #1989
- env: TESTENV=py27-trial
- env: TESTENV=py35-trial
include: include:
- env: TESTENV=py36 - env: TESTENV=py36
python: '3.6-dev' python: '3.6-dev'
- env: TESTENV=py37
python: 'nightly'
script: tox --recreate -e $TESTENV script: tox --recreate -e $TESTENV

View File

@ -48,6 +48,7 @@ Duncan Betts
Edison Gustavo Muenz Edison Gustavo Muenz
Edoardo Batini Edoardo Batini
Eduardo Schettino Eduardo Schettino
Eli Boyarski
Elizaveta Shashkova Elizaveta Shashkova
Endre Galaczi Endre Galaczi
Eric Hunsberger Eric Hunsberger
@ -71,6 +72,7 @@ Janne Vanhala
Jason R. Coombs Jason R. Coombs
Javier Domingo Cansino Javier Domingo Cansino
Javier Romero Javier Romero
Jeff Widman
John Towler John Towler
Jon Sonesen Jon Sonesen
Jordan Guymon Jordan Guymon
@ -142,6 +144,7 @@ Tom Viner
Trevor Bekolay Trevor Bekolay
Tyler Goodlet Tyler Goodlet
Vasily Kuznetsov Vasily Kuznetsov
Victor Uriarte
Vlad Dragos Vlad Dragos
Wouter van Ackooy Wouter van Ackooy
Xuecong Liao Xuecong Liao

View File

@ -54,7 +54,6 @@ Changes
.. _@mattduck: https://github.com/mattduck .. _@mattduck: https://github.com/mattduck
.. _@wheerd: https://github.com/wheerd .. _@wheerd: https://github.com/wheerd
.. _@fogo: https://github.com/fogo .. _@fogo: https://github.com/fogo
.. _@lesteve: https://github.com/lesteve
.. _@mandeep: https://github.com/mandeep .. _@mandeep: https://github.com/mandeep
.. _@unsignedint: https://github.com/unsignedint .. _@unsignedint: https://github.com/unsignedint
@ -68,30 +67,63 @@ Changes
.. _#2147: https://github.com/pytest-dev/pytest/issues/2147 .. _#2147: https://github.com/pytest-dev/pytest/issues/2147
.. _#2208: https://github.com/pytest-dev/pytest/issues/2208 .. _#2208: https://github.com/pytest-dev/pytest/issues/2208
3.0.6.dev0 (unreleased) 3.0.7 (unreleased)
======================= =======================
* *
*
*
*
3.0.6 (2017-01-22)
==================
* pytest no longer generates ``PendingDeprecationWarning`` from its own operations, which was introduced by mistake in version ``3.0.5`` (`#2118`_).
Thanks to `@nicoddemus`_ for the report and `@RonnyPfannschmidt`_ for the PR.
* pytest no longer recognizes coroutine functions as yield tests (`#2129`_). * pytest no longer recognizes coroutine functions as yield tests (`#2129`_).
Thanks to `@malinoff`_ for the PR. Thanks to `@malinoff`_ for the PR.
* Plugins loaded by the ``PYTEST_PLUGINS`` environment variable are now automatically
considered for assertion rewriting (`#2185`_).
Thanks `@nicoddemus`_ for the PR.
* Improve error message when pytest.warns fails (`#2150`_). The type(s) of the * Improve error message when pytest.warns fails (`#2150`_). The type(s) of the
expected warnings and the list of caught warnings is added to the expected warnings and the list of caught warnings is added to the
error message. Thanks `@lesteve`_ for the PR. error message. Thanks `@lesteve`_ for the PR.
* Fix ``pytester`` internal plugin to work correctly with latest versions of
``zope.interface`` (`#1989`_). Thanks `@nicoddemus`_ for the PR.
* Assert statements of the ``pytester`` plugin again benefit from assertion rewriting (`#1920`_).
Thanks `@RonnyPfannschmidt`_ for the report and `@nicoddemus`_ for the PR.
* Specifying tests with colons like ``test_foo.py::test_bar`` for tests in * Specifying tests with colons like ``test_foo.py::test_bar`` for tests in
subdirectories with ini configuration files now uses the correct ini file subdirectories with ini configuration files now uses the correct ini file
(`#2148`_). Thanks `@pelme`_. (`#2148`_). Thanks `@pelme`_.
* * Fail ``testdir.runpytest().assert_outcomes()`` explicitly if the pytest
terminal output it relies on is missing. Thanks to `@eli-b`_ for the PR.
.. _@lesteve: https://github.com/lesteve
.. _@malinoff: https://github.com/malinoff .. _@malinoff: https://github.com/malinoff
.. _@pelme: https://github.com/pelme .. _@pelme: https://github.com/pelme
.. _@eli-b: https://github.com/eli-b
.. _#2118: https://github.com/pytest-dev/pytest/issues/2118
.. _#1989: https://github.com/pytest-dev/pytest/issues/1989
.. _#1920: https://github.com/pytest-dev/pytest/issues/1920
.. _#2129: https://github.com/pytest-dev/pytest/issues/2129 .. _#2129: https://github.com/pytest-dev/pytest/issues/2129
.. _#2148: https://github.com/pytest-dev/pytest/issues/2148 .. _#2148: https://github.com/pytest-dev/pytest/issues/2148
.. _#2150: https://github.com/pytest-dev/pytest/issues/2150 .. _#2150: https://github.com/pytest-dev/pytest/issues/2150
.. _#2185: https://github.com/pytest-dev/pytest/issues/2185
3.0.5 (2016-12-05) 3.0.5 (2016-12-05)
@ -761,7 +793,7 @@ time or change existing behaviors in order to make them less surprising/more use
Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_ Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_
for PR the (`#1524`_). for PR the (`#1524`_).
* Fix win32 path issue when puttinging custom config file with absolute path * Fix win32 path issue when putting custom config file with absolute path
in ``pytest.main("-c your_absolute_path")``. in ``pytest.main("-c your_absolute_path")``.
* Fix maximum recursion depth detection when raised error class is not aware * Fix maximum recursion depth detection when raised error class is not aware
@ -1093,7 +1125,7 @@ time or change existing behaviors in order to make them less surprising/more use
- (experimental) adapt more SEMVER style versioning and change meaning of - (experimental) adapt more SEMVER style versioning and change meaning of
master branch in git repo: "master" branch now keeps the bugfixes, changes master branch in git repo: "master" branch now keeps the bugfixes, changes
aimed for micro releases. "features" branch will only be be released aimed for micro releases. "features" branch will only be released
with minor or major pytest releases. with minor or major pytest releases.
- Fix issue #766 by removing documentation references to distutils. - Fix issue #766 by removing documentation references to distutils.
@ -1227,7 +1259,7 @@ time or change existing behaviors in order to make them less surprising/more use
- new option ``--import-mode`` to allow to change test module importing - new option ``--import-mode`` to allow to change test module importing
behaviour to append to sys.path instead of prepending. This better allows behaviour to append to sys.path instead of prepending. This better allows
to run test modules against installated versions of a package even if the to run test modules against installed versions of a package even if the
package under test has the same import root. In this example:: package under test has the same import root. In this example::
testing/__init__.py testing/__init__.py
@ -1385,7 +1417,7 @@ time or change existing behaviors in order to make them less surprising/more use
explanations. Thanks Carl Meyer for the report and test case. explanations. Thanks Carl Meyer for the report and test case.
- fix issue553: properly handling inspect.getsourcelines failures in - fix issue553: properly handling inspect.getsourcelines failures in
FixtureLookupError which would lead to to an internal error, FixtureLookupError which would lead to an internal error,
obfuscating the original problem. Thanks talljosh for initial obfuscating the original problem. Thanks talljosh for initial
diagnose/patch and Bruno Oliveira for final patch. diagnose/patch and Bruno Oliveira for final patch.
@ -1528,7 +1560,7 @@ time or change existing behaviors in order to make them less surprising/more use
- fix conftest related fixture visibility issue: when running with a - fix conftest related fixture visibility issue: when running with a
CWD outside of a test package pytest would get fixture discovery wrong. CWD outside of a test package pytest would get fixture discovery wrong.
Thanks to Wolfgang Schnerring for figuring out a reproducable example. Thanks to Wolfgang Schnerring for figuring out a reproducible example.
- Introduce pytest_enter_pdb hook (needed e.g. by pytest_timeout to cancel the - Introduce pytest_enter_pdb hook (needed e.g. by pytest_timeout to cancel the
timeout when interactively entering pdb). Thanks Wolfgang Schnerring. timeout when interactively entering pdb). Thanks Wolfgang Schnerring.
@ -1727,7 +1759,7 @@ time or change existing behaviors in order to make them less surprising/more use
- fix issue429: comparing byte strings with non-ascii chars in assert - fix issue429: comparing byte strings with non-ascii chars in assert
expressions now work better. Thanks Floris Bruynooghe. expressions now work better. Thanks Floris Bruynooghe.
- make capfd/capsys.capture private, its unused and shouldnt be exposed - make capfd/capsys.capture private, its unused and shouldn't be exposed
2.5.1 (2013-12-17) 2.5.1 (2013-12-17)
@ -1784,7 +1816,7 @@ time or change existing behaviors in order to make them less surprising/more use
to problems for more than >966 non-function scoped parameters). to problems for more than >966 non-function scoped parameters).
- fix issue290 - there is preliminary support now for parametrizing - fix issue290 - there is preliminary support now for parametrizing
with repeated same values (sometimes useful to to test if calling with repeated same values (sometimes useful to test if calling
a second time works as with the first time). a second time works as with the first time).
- close issue240 - document precisely how pytest module importing - close issue240 - document precisely how pytest module importing
@ -1998,7 +2030,7 @@ new features:
- fix issue322: tearDownClass is not run if setUpClass failed. Thanks - fix issue322: tearDownClass is not run if setUpClass failed. Thanks
Mathieu Agopian for the initial fix. Also make all of pytest/nose Mathieu Agopian for the initial fix. Also make all of pytest/nose
finalizer mimick the same generic behaviour: if a setupX exists and finalizer mimic the same generic behaviour: if a setupX exists and
fails, don't run teardownX. This internally introduces a new method fails, don't run teardownX. This internally introduces a new method
"node.addfinalizer()" helper which can only be called during the setup "node.addfinalizer()" helper which can only be called during the setup
phase of a node. phase of a node.
@ -2117,11 +2149,11 @@ Bug fixes:
(thanks Adam Goucher) (thanks Adam Goucher)
- Issue 265 - integrate nose setup/teardown with setupstate - Issue 265 - integrate nose setup/teardown with setupstate
so it doesnt try to teardown if it did not setup so it doesn't try to teardown if it did not setup
- issue 271 - dont write junitxml on slave nodes - issue 271 - don't write junitxml on slave nodes
- Issue 274 - dont try to show full doctest example - Issue 274 - don't try to show full doctest example
when doctest does not know the example location when doctest does not know the example location
- issue 280 - disable assertion rewriting on buggy CPython 2.6.0 - issue 280 - disable assertion rewriting on buggy CPython 2.6.0
@ -2157,7 +2189,7 @@ Bug fixes:
- allow to specify prefixes starting with "_" when - allow to specify prefixes starting with "_" when
customizing python_functions test discovery. (thanks Graham Horler) customizing python_functions test discovery. (thanks Graham Horler)
- improve PYTEST_DEBUG tracing output by puting - improve PYTEST_DEBUG tracing output by putting
extra data on a new lines with additional indent extra data on a new lines with additional indent
- ensure OutcomeExceptions like skip/fail have initialized exception attributes - ensure OutcomeExceptions like skip/fail have initialized exception attributes
@ -2206,7 +2238,7 @@ Bug fixes:
- fix issue209 - reintroduce python2.4 support by depending on newer - fix issue209 - reintroduce python2.4 support by depending on newer
pylib which re-introduced statement-finding for pre-AST interpreters pylib which re-introduced statement-finding for pre-AST interpreters
- nose support: only call setup if its a callable, thanks Andrew - nose support: only call setup if it's a callable, thanks Andrew
Taumoefolau Taumoefolau
- fix issue219 - add py2.4-3.3 classifiers to TROVE list - fix issue219 - add py2.4-3.3 classifiers to TROVE list
@ -2302,7 +2334,7 @@ Bug fixes:
- fix issue128: show captured output when capsys/capfd are used - fix issue128: show captured output when capsys/capfd are used
- fix issue179: propperly show the dependency chain of factories - fix issue179: properly show the dependency chain of factories
- pluginmanager.register(...) now raises ValueError if the - pluginmanager.register(...) now raises ValueError if the
plugin has been already registered or the name is taken plugin has been already registered or the name is taken
@ -2343,7 +2375,7 @@ Bug fixes:
- don't show deselected reason line if there is none - don't show deselected reason line if there is none
- py.test -vv will show all of assert comparisations instead of truncating - py.test -vv will show all of assert comparisons instead of truncating
2.2.4 (2012-05-22) 2.2.4 (2012-05-22)
================== ==================
@ -2354,7 +2386,7 @@ Bug fixes:
- fix issue with unittest: now @unittest.expectedFailure markers should - fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers) be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands - document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions - fix issue 140: properly get the real functions
of bound classmethods for setup/teardown_class of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net - fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when - fix issue #143: call unconfigure/sessionfinish always when
@ -2365,7 +2397,7 @@ Bug fixes:
2.2.3 (2012-02-05) 2.2.3 (2012-02-05)
================== ==================
- fix uploaded package to only include neccesary files - fix uploaded package to only include necessary files
2.2.2 (2012-02-05) 2.2.2 (2012-02-05)
================== ==================
@ -2506,7 +2538,7 @@ Bug fixes:
- don't require zlib (and other libs) for genscript plugin without - don't require zlib (and other libs) for genscript plugin without
--genscript actually being used. --genscript actually being used.
- speed up skips (by not doing a full traceback represenation - speed up skips (by not doing a full traceback representation
internally) internally)
- fix issue37: avoid invalid characters in junitxml's output - fix issue37: avoid invalid characters in junitxml's output
@ -2554,9 +2586,9 @@ Bug fixes:
this. this.
- fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular - fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular
thanks to Laura Creighton who also revieved parts of the documentation. thanks to Laura Creighton who also reviewed parts of the documentation.
- fix slighly wrong output of verbose progress reporting for classes - fix slightly wrong output of verbose progress reporting for classes
(thanks Amaury) (thanks Amaury)
- more precise (avoiding of) deprecation warnings for node.Class|Function accesses - more precise (avoiding of) deprecation warnings for node.Class|Function accesses
@ -2617,7 +2649,7 @@ Bug fixes:
- pytest-2.0 is now its own package and depends on pylib-2.0 - pytest-2.0 is now its own package and depends on pylib-2.0
- new ability: python -m pytest / python -m pytest.main ability - new ability: python -m pytest / python -m pytest.main ability
- new python invcation: pytest.main(args, plugins) to load - new python invocation: pytest.main(args, plugins) to load
some custom plugins early. some custom plugins early.
- try harder to run unittest test suites in a more compatible manner - try harder to run unittest test suites in a more compatible manner
by deferring setup/teardown semantics to the unittest package. by deferring setup/teardown semantics to the unittest package.
@ -2856,7 +2888,7 @@ Bug fixes:
- extend and refine xfail mechanism: - extend and refine xfail mechanism:
``@py.test.mark.xfail(run=False)`` do not run the decorated test ``@py.test.mark.xfail(run=False)`` do not run the decorated test
``@py.test.mark.xfail(reason="...")`` prints the reason string in xfail summaries ``@py.test.mark.xfail(reason="...")`` prints the reason string in xfail summaries
specifiying ``--runxfail`` on command line virtually ignores xfail markers specifying ``--runxfail`` on command line virtually ignores xfail markers
- expose (previously internal) commonly useful methods: - expose (previously internal) commonly useful methods:
py.io.get_terminal_with() -> return terminal width py.io.get_terminal_with() -> return terminal width
@ -3081,7 +3113,7 @@ Bug fixes:
* add the ability to specify a path for py.lookup to search in * add the ability to specify a path for py.lookup to search in
* fix a funcarg cached_setup bug probably only occuring * fix a funcarg cached_setup bug probably only occurring
in distributed testing and "module" scope with teardown. in distributed testing and "module" scope with teardown.
* many fixes and changes for making the code base python3 compatible, * many fixes and changes for making the code base python3 compatible,
@ -3347,10 +3379,10 @@ serve as a reference for developers.
* fixed issue with 2.5 type representations in py.test [45483, 45484] * fixed issue with 2.5 type representations in py.test [45483, 45484]
* made that internal reporting issues displaying is done atomically in py.test * made that internal reporting issues displaying is done atomically in py.test
[45518] [45518]
* made that non-existing files are igored by the py.lookup script [45519] * made that non-existing files are ignored by the py.lookup script [45519]
* improved exception name creation in py.test [45535] * improved exception name creation in py.test [45535]
* made that less threads are used in execnet [merge in 45539] * made that less threads are used in execnet [merge in 45539]
* removed lock required for atomical reporting issue displaying in py.test * removed lock required for atomic reporting issue displaying in py.test
[45545] [45545]
* removed globals from execnet [45541, 45547] * removed globals from execnet [45541, 45547]
* refactored cleanup mechanics, made that setDaemon is set to 1 to make atexit * refactored cleanup mechanics, made that setDaemon is set to 1 to make atexit

View File

@ -402,17 +402,11 @@ class PytestPluginManager(PluginManager):
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS")) self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS"))
def consider_module(self, mod): def consider_module(self, mod):
plugins = getattr(mod, 'pytest_plugins', []) self._import_plugin_specs(getattr(mod, 'pytest_plugins', []))
if isinstance(plugins, str):
plugins = [plugins]
self.rewrite_hook.mark_rewrite(*plugins)
self._import_plugin_specs(plugins)
def _import_plugin_specs(self, spec): def _import_plugin_specs(self, spec):
if spec: plugins = _get_plugin_specs_as_list(spec)
if isinstance(spec, str): for import_spec in plugins:
spec = spec.split(",")
for import_spec in spec:
self.import_plugin(import_spec) self.import_plugin(import_spec)
def import_plugin(self, modname): def import_plugin(self, modname):
@ -420,13 +414,14 @@ class PytestPluginManager(PluginManager):
# "terminal" or "capture". Those plugins are registered under their # "terminal" or "capture". Those plugins are registered under their
# basename for historic purposes but must be imported with the # basename for historic purposes but must be imported with the
# _pytest prefix. # _pytest prefix.
assert isinstance(modname, str) assert isinstance(modname, str), "module name as string required, got %r" % modname
if self.get_plugin(modname) is not None: if self.get_plugin(modname) is not None:
return return
if modname in builtin_plugins: if modname in builtin_plugins:
importspec = "_pytest." + modname importspec = "_pytest." + modname
else: else:
importspec = modname importspec = modname
self.rewrite_hook.mark_rewrite(importspec)
try: try:
__import__(importspec) __import__(importspec)
except ImportError as e: except ImportError as e:
@ -447,6 +442,24 @@ class PytestPluginManager(PluginManager):
self.consider_module(mod) self.consider_module(mod)
def _get_plugin_specs_as_list(specs):
"""
Parses a list of "plugin specs" and returns a list of plugin names.
Plugin specs can be given as a list of strings separated by "," or already as a list/tuple in
which case it is returned as a list. Specs can also be `None` in which case an
empty list is returned.
"""
if specs is not None:
if isinstance(specs, str):
specs = specs.split(',') if specs else []
if not isinstance(specs, (list, tuple)):
raise UsageError("Plugin specs must be a ','-separated string or a "
"list/tuple of strings for plugin names. Given: %r" % specs)
return list(specs)
return []
class Parser(object): class Parser(object):
""" Parser for command line arguments and ini-file values. """ Parser for command line arguments and ini-file values.

View File

@ -190,14 +190,22 @@ class FSHookProxy(object):
self.__dict__[name] = x self.__dict__[name] = x
return x return x
def compatproperty(name): class _CompatProperty(object):
def fget(self): def __init__(self, name):
import warnings self.name = name
warnings.warn("This usage is deprecated, please use pytest.{0} instead".format(name),
PendingDeprecationWarning, stacklevel=2) def __get__(self, obj, owner):
return getattr(pytest, name) if obj is None:
return self
# TODO: reenable in the features branch
# warnings.warn(
# "usage of {owner!r}.{name} is deprecated, please use pytest.{name} instead".format(
# name=self.name, owner=type(owner).__name__),
# PendingDeprecationWarning, stacklevel=2)
return getattr(pytest, self.name)
return property(fget)
class NodeKeywords(MappingMixin): class NodeKeywords(MappingMixin):
def __init__(self, node): def __init__(self, node):
@ -269,19 +277,23 @@ class Node(object):
""" fspath sensitive hook proxy used to call pytest hooks""" """ fspath sensitive hook proxy used to call pytest hooks"""
return self.session.gethookproxy(self.fspath) return self.session.gethookproxy(self.fspath)
Module = compatproperty("Module") Module = _CompatProperty("Module")
Class = compatproperty("Class") Class = _CompatProperty("Class")
Instance = compatproperty("Instance") Instance = _CompatProperty("Instance")
Function = compatproperty("Function") Function = _CompatProperty("Function")
File = compatproperty("File") File = _CompatProperty("File")
Item = compatproperty("Item") Item = _CompatProperty("Item")
def _getcustomclass(self, name): def _getcustomclass(self, name):
maybe_compatprop = getattr(type(self), name)
if isinstance(maybe_compatprop, _CompatProperty):
return getattr(pytest, name)
else:
cls = getattr(self, name) cls = getattr(self, name)
if cls != getattr(pytest, name): # TODO: reenable in the features branch
py.log._apiwarn("2.0", "use of node.%s is deprecated, " # warnings.warn("use of node.%s is deprecated, "
"use pytest_pycollect_makeitem(...) to create custom " # "use pytest_pycollect_makeitem(...) to create custom "
"collection nodes" % name) # "collection nodes" % name, category=DeprecationWarning)
return cls return cls
def __repr__(self): def __repr__(self):

View File

@ -11,7 +11,7 @@ RE_IMPORT_ERROR_NAME = re.compile("^No module named (.*)$")
@pytest.fixture @pytest.fixture
def monkeypatch(request): def monkeypatch():
"""The returned ``monkeypatch`` fixture provides these """The returned ``monkeypatch`` fixture provides these
helper methods to modify objects, dictionaries or os.environ:: helper methods to modify objects, dictionaries or os.environ::
@ -30,8 +30,8 @@ def monkeypatch(request):
will be raised if the set/deletion operation has no target. will be raised if the set/deletion operation has no target.
""" """
mpatch = MonkeyPatch() mpatch = MonkeyPatch()
request.addfinalizer(mpatch.undo) yield mpatch
return mpatch mpatch.undo()
def resolve(name): def resolve(name):

View File

@ -369,6 +369,7 @@ class RunResult(object):
for num, cat in outcomes: for num, cat in outcomes:
d[cat] = int(num) d[cat] = int(num)
return d return d
raise ValueError("Pytest terminal report not found")
def assert_outcomes(self, passed=0, skipped=0, failed=0): def assert_outcomes(self, passed=0, skipped=0, failed=0):
""" assert that the specified outcomes appear with the respective """ assert that the specified outcomes appear with the respective
@ -449,9 +450,9 @@ class Testdir(object):
the module is re-imported. the module is re-imported.
""" """
for name in set(sys.modules).difference(self._savemodulekeys): for name in set(sys.modules).difference(self._savemodulekeys):
# it seems zope.interfaces is keeping some state # zope.interface (used by twisted-related tests) keeps internal
# (used by twisted related tests) # state and can't be deleted
if name != "zope.interface": if not name.startswith("zope.interface"):
del sys.modules[name] del sys.modules[name]
def make_hook_recorder(self, pluginmanager): def make_hook_recorder(self, pluginmanager):

View File

@ -46,7 +46,7 @@ def pytest_configure(config):
) )
config.addinivalue_line("markers", config.addinivalue_line("markers",
"xfail(condition, reason=None, run=True, raises=None, strict=False): " "xfail(condition, reason=None, run=True, raises=None, strict=False): "
"mark the the test function as an expected failure if eval(condition) " "mark the test function as an expected failure if eval(condition) "
"has a True value. Optionally specify a reason for better reporting " "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. " "and run=False if you don't even want to execute the test function. "
"If only specific exception(s) are expected, you can list them in " "If only specific exception(s) are expected, you can list them in "

View File

@ -15,6 +15,7 @@ environment:
- TOXENV: "py33" - TOXENV: "py33"
- TOXENV: "py34" - TOXENV: "py34"
- TOXENV: "py35" - TOXENV: "py35"
- TOXENV: "py36"
- TOXENV: "pypy" - TOXENV: "pypy"
- TOXENV: "py27-pexpect" - TOXENV: "py27-pexpect"
- TOXENV: "py27-xdist" - TOXENV: "py27-xdist"
@ -27,12 +28,6 @@ environment:
- TOXENV: "freeze" - TOXENV: "freeze"
- TOXENV: "docs" - TOXENV: "docs"
matrix:
allow_failures:
# see #1989
- TOXENV: "py27-trial"
- TOXENV: "py35-trial"
install: install:
- echo Installed Pythons - echo Installed Pythons
- dir c:\Python* - dir c:\Python*

View File

@ -6,6 +6,7 @@ Release announcements
:maxdepth: 2 :maxdepth: 2
release-3.0.6
release-3.0.5 release-3.0.5
release-3.0.4 release-3.0.4
release-3.0.3 release-3.0.3

View File

@ -63,9 +63,9 @@ Changes between 2.0.1 and 2.0.2
this. this.
- fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular - fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular
thanks to Laura Creighton who also revieved parts of the documentation. thanks to Laura Creighton who also reviewed parts of the documentation.
- fix slighly wrong output of verbose progress reporting for classes - fix slightly wrong output of verbose progress reporting for classes
(thanks Amaury) (thanks Amaury)
- more precise (avoiding of) deprecation warnings for node.Class|Function accesses - more precise (avoiding of) deprecation warnings for node.Class|Function accesses

View File

@ -13,7 +13,7 @@ If you want to install or upgrade pytest, just type one of::
easy_install -U pytest easy_install -U pytest
There also is a bugfix release 1.6 of pytest-xdist, the plugin There also is a bugfix release 1.6 of pytest-xdist, the plugin
that enables seemless distributed and "looponfail" testing for Python. that enables seamless distributed and "looponfail" testing for Python.
best, best,
holger krekel holger krekel
@ -33,7 +33,7 @@ Changes between 2.0.2 and 2.0.3
- don't require zlib (and other libs) for genscript plugin without - don't require zlib (and other libs) for genscript plugin without
--genscript actually being used. --genscript actually being used.
- speed up skips (by not doing a full traceback represenation - speed up skips (by not doing a full traceback representation
internally) internally)
- fix issue37: avoid invalid characters in junitxml's output - fix issue37: avoid invalid characters in junitxml's output

View File

@ -2,7 +2,7 @@ pytest-2.2.1: bug fixes, perfect teardowns
=========================================================================== ===========================================================================
pytest-2.2.1 is a minor backward-compatible release of the the py.test pytest-2.2.1 is a minor backward-compatible release of the py.test
testing tool. It contains bug fixes and little improvements, including testing tool. It contains bug fixes and little improvements, including
documentation fixes. If you are using the distributed testing documentation fixes. If you are using the distributed testing
pluginmake sure to upgrade it to pytest-xdist-1.8. pluginmake sure to upgrade it to pytest-xdist-1.8.

View File

@ -29,7 +29,7 @@ Changes between 2.2.3 and 2.2.4
- fix issue with unittest: now @unittest.expectedFailure markers should - fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers) be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands - document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions - fix issue 140: properly get the real functions
of bound classmethods for setup/teardown_class of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net - fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when - fix issue #143: call unconfigure/sessionfinish always when

View File

@ -89,7 +89,7 @@ Changes between 2.2.4 and 2.3.0
- fix issue128: show captured output when capsys/capfd are used - fix issue128: show captured output when capsys/capfd are used
- fix issue179: propperly show the dependency chain of factories - fix issue179: properly show the dependency chain of factories
- pluginmanager.register(...) now raises ValueError if the - pluginmanager.register(...) now raises ValueError if the
plugin has been already registered or the name is taken plugin has been already registered or the name is taken
@ -130,5 +130,5 @@ Changes between 2.2.4 and 2.3.0
- don't show deselected reason line if there is none - don't show deselected reason line if there is none
- py.test -vv will show all of assert comparisations instead of truncating - py.test -vv will show all of assert comparisons instead of truncating

View File

@ -1,7 +1,7 @@
pytest-2.3.2: some fixes and more traceback-printing speed pytest-2.3.2: some fixes and more traceback-printing speed
=========================================================================== ===========================================================================
pytest-2.3.2 is a another stabilization release: pytest-2.3.2 is another stabilization release:
- issue 205: fixes a regression with conftest detection - issue 205: fixes a regression with conftest detection
- issue 208/29: fixes traceback-printing speed in some bad cases - issue 208/29: fixes traceback-printing speed in some bad cases

View File

@ -1,7 +1,7 @@
pytest-2.3.3: integration fixes, py24 suport, ``*/**`` shown in traceback pytest-2.3.3: integration fixes, py24 support, ``*/**`` shown in traceback
=========================================================================== ===========================================================================
pytest-2.3.3 is a another stabilization release of the py.test tool pytest-2.3.3 is another stabilization release of the py.test tool
which offers uebersimple assertions, scalable fixture mechanisms which offers uebersimple assertions, scalable fixture mechanisms
and deep customization for testing with Python. Particularly, and deep customization for testing with Python. Particularly,
this release provides: this release provides:
@ -46,7 +46,7 @@ Changes between 2.3.2 and 2.3.3
- fix issue209 - reintroduce python2.4 support by depending on newer - fix issue209 - reintroduce python2.4 support by depending on newer
pylib which re-introduced statement-finding for pre-AST interpreters pylib which re-introduced statement-finding for pre-AST interpreters
- nose support: only call setup if its a callable, thanks Andrew - nose support: only call setup if it's a callable, thanks Andrew
Taumoefolau Taumoefolau
- fix issue219 - add py2.4-3.3 classifiers to TROVE list - fix issue219 - add py2.4-3.3 classifiers to TROVE list

View File

@ -44,11 +44,11 @@ Changes between 2.3.4 and 2.3.5
(thanks Adam Goucher) (thanks Adam Goucher)
- Issue 265 - integrate nose setup/teardown with setupstate - Issue 265 - integrate nose setup/teardown with setupstate
so it doesnt try to teardown if it did not setup so it doesn't try to teardown if it did not setup
- issue 271 - dont write junitxml on slave nodes - issue 271 - don't write junitxml on slave nodes
- Issue 274 - dont try to show full doctest example - Issue 274 - don't try to show full doctest example
when doctest does not know the example location when doctest does not know the example location
- issue 280 - disable assertion rewriting on buggy CPython 2.6.0 - issue 280 - disable assertion rewriting on buggy CPython 2.6.0
@ -84,7 +84,7 @@ Changes between 2.3.4 and 2.3.5
- allow to specify prefixes starting with "_" when - allow to specify prefixes starting with "_" when
customizing python_functions test discovery. (thanks Graham Horler) customizing python_functions test discovery. (thanks Graham Horler)
- improve PYTEST_DEBUG tracing output by puting - improve PYTEST_DEBUG tracing output by putting
extra data on a new lines with additional indent extra data on a new lines with additional indent
- ensure OutcomeExceptions like skip/fail have initialized exception attributes - ensure OutcomeExceptions like skip/fail have initialized exception attributes

View File

@ -36,7 +36,7 @@ a full list of details. A few feature highlights:
- reporting: color the last line red or green depending if - reporting: color the last line red or green depending if
failures/errors occurred or everything passed. failures/errors occurred or everything passed.
The documentation has been updated to accomodate the changes, The documentation has been updated to accommodate the changes,
see `http://pytest.org <http://pytest.org>`_ see `http://pytest.org <http://pytest.org>`_
To install or upgrade pytest:: To install or upgrade pytest::
@ -118,7 +118,7 @@ new features:
- fix issue322: tearDownClass is not run if setUpClass failed. Thanks - fix issue322: tearDownClass is not run if setUpClass failed. Thanks
Mathieu Agopian for the initial fix. Also make all of pytest/nose Mathieu Agopian for the initial fix. Also make all of pytest/nose
finalizer mimick the same generic behaviour: if a setupX exists and finalizer mimic the same generic behaviour: if a setupX exists and
fails, don't run teardownX. This internally introduces a new method fails, don't run teardownX. This internally introduces a new method
"node.addfinalizer()" helper which can only be called during the setup "node.addfinalizer()" helper which can only be called during the setup
phase of a node. phase of a node.

View File

@ -70,7 +70,7 @@ holger krekel
to problems for more than >966 non-function scoped parameters). to problems for more than >966 non-function scoped parameters).
- fix issue290 - there is preliminary support now for parametrizing - fix issue290 - there is preliminary support now for parametrizing
with repeated same values (sometimes useful to to test if calling with repeated same values (sometimes useful to test if calling
a second time works as with the first time). a second time works as with the first time).
- close issue240 - document precisely how pytest module importing - close issue240 - document precisely how pytest module importing
@ -149,7 +149,7 @@ holger krekel
would not work correctly because pytest assumes @pytest.mark.some would not work correctly because pytest assumes @pytest.mark.some
gets a function to be decorated already. We now at least detect if this gets a function to be decorated already. We now at least detect if this
arg is an lambda and thus the example will work. Thanks Alex Gaynor arg is a lambda and thus the example will work. Thanks Alex Gaynor
for bringing it up. for bringing it up.
- xfail a test on pypy that checks wrong encoding/ascii (pypy does - xfail a test on pypy that checks wrong encoding/ascii (pypy does

View File

@ -60,5 +60,5 @@ holger krekel
- fix issue429: comparing byte strings with non-ascii chars in assert - fix issue429: comparing byte strings with non-ascii chars in assert
expressions now work better. Thanks Floris Bruynooghe. expressions now work better. Thanks Floris Bruynooghe.
- make capfd/capsys.capture private, its unused and shouldnt be exposed - make capfd/capsys.capture private, its unused and shouldn't be exposed

View File

@ -42,7 +42,7 @@ Changes 2.6.3
- fix conftest related fixture visibility issue: when running with a - fix conftest related fixture visibility issue: when running with a
CWD outside of a test package pytest would get fixture discovery wrong. CWD outside of a test package pytest would get fixture discovery wrong.
Thanks to Wolfgang Schnerring for figuring out a reproducable example. Thanks to Wolfgang Schnerring for figuring out a reproducible example.
- Introduce pytest_enter_pdb hook (needed e.g. by pytest_timeout to cancel the - Introduce pytest_enter_pdb hook (needed e.g. by pytest_timeout to cancel the
timeout when interactively entering pdb). Thanks Wolfgang Schnerring. timeout when interactively entering pdb). Thanks Wolfgang Schnerring.

View File

@ -32,7 +32,7 @@ The py.test Development Team
explanations. Thanks Carl Meyer for the report and test case. explanations. Thanks Carl Meyer for the report and test case.
- fix issue553: properly handling inspect.getsourcelines failures in - fix issue553: properly handling inspect.getsourcelines failures in
FixtureLookupError which would lead to to an internal error, FixtureLookupError which would lead to an internal error,
obfuscating the original problem. Thanks talljosh for initial obfuscating the original problem. Thanks talljosh for initial
diagnose/patch and Bruno Oliveira for final patch. diagnose/patch and Bruno Oliveira for final patch.

View File

@ -46,7 +46,7 @@ The py.test Development Team
Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_ Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_
for PR the (`#1524`_). for PR the (`#1524`_).
* Fix win32 path issue when puttinging custom config file with absolute path * Fix win32 path issue when putting custom config file with absolute path
in ``pytest.main("-c your_absolute_path")``. in ``pytest.main("-c your_absolute_path")``.
* Fix maximum recursion depth detection when raised error class is not aware * Fix maximum recursion depth detection when raised error class is not aware

View File

@ -0,0 +1,33 @@
pytest-3.0.6
============
pytest 3.0.6 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at http://doc.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Andreas Pelme
* Bruno Oliveira
* Dmitry Malinovsky
* Eli Boyarski
* Jakub Wilk
* Jeff Widman
* Loïc Estève
* Luke Murphy
* Miro Hrončok
* Oscar Hellström
* Peter Heatwole
* Philippe Ombredanne
* Ronny Pfannschmidt
* Rutger Prins
* Stefan Scherfke
Happy testing,
The pytest Development Team

View File

@ -26,7 +26,7 @@ you will see the return value of the function call::
$ pytest test_assert1.py $ pytest test_assert1.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -170,7 +170,7 @@ if you run this module::
$ pytest test_assert2.py $ pytest test_assert2.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -262,50 +262,20 @@ Advanced assertion introspection
.. versionadded:: 2.1 .. versionadded:: 2.1
Reporting details about a failing assertion is achieved either by rewriting Reporting details about a failing assertion is achieved by rewriting assert
assert statements before they are run or re-evaluating the assert expression and statements before they are run. Rewritten assert statements put introspection
recording the intermediate values. Which technique is used depends on the information into the assertion failure message. ``pytest`` only rewrites test
location of the assert, ``pytest`` configuration, and Python version being used modules directly discovered by its test collection process, so asserts in
to run ``pytest``. supporting modules which are not themselves test modules will not be rewritten.
By default, ``pytest`` rewrites assert statements in test modules.
Rewritten assert statements put introspection information into the assertion failure message.
``pytest`` only rewrites test modules directly discovered by its test collection process, so
asserts in supporting modules which are not themselves test modules will not be
rewritten.
.. note:: .. note::
``pytest`` rewrites test modules on import. It does this by using an import ``pytest`` rewrites test modules on import. It does this by using an import
hook to write a new pyc files. Most of the time this works transparently. hook to write new pyc files. Most of the time this works transparently.
However, if you are messing with import yourself, the import hook may However, if you are messing with import yourself, the import hook may
interfere. If this is the case, simply use ``--assert=reinterp`` or interfere. If this is the case, use ``--assert=plain``. Additionally,
``--assert=plain``. Additionally, rewriting will fail silently if it cannot rewriting will fail silently if it cannot write new pycs, i.e. in a read-only
write new pycs, i.e. in a read-only filesystem or a zipfile. filesystem or a zipfile.
If an assert statement has not been rewritten or the Python version is less than
2.6, ``pytest`` falls back on assert reinterpretation. In assert
reinterpretation, ``pytest`` walks the frame of the function containing the
assert statement to discover sub-expression results of the failing assert
statement. You can force ``pytest`` to always use assertion reinterpretation by
passing the ``--assert=reinterp`` option.
Assert reinterpretation has a caveat not present with assert rewriting: If
evaluating the assert expression has side effects you may get a warning that the
intermediate values could not be determined safely. A common example of this
issue is an assertion which reads from a file::
assert f.read() != '...'
If this assertion fails then the re-evaluation will probably succeed!
This is because ``f.read()`` will return an empty string when it is
called the second time during the re-evaluation. However, it is
easy to rewrite the assertion and avoid any trouble::
content = f.read()
assert content != '...'
All assert introspection can be turned off by passing ``--assert=plain``.
For further information, Benjamin Peterson wrote up `Behind the scenes of pytest's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_. For further information, Benjamin Peterson wrote up `Behind the scenes of pytest's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_.
@ -318,3 +288,4 @@ For further information, Benjamin Peterson wrote up `Behind the scenes of pytest
.. versionchanged:: 3.0 .. versionchanged:: 3.0
Removes the ``--no-assert`` and``--nomagic`` options. Removes the ``--no-assert`` and``--nomagic`` options.
Removes the ``--assert=reinterp`` option.

View File

@ -80,7 +80,7 @@ If you then run it with ``--lf``::
$ pytest --lf $ pytest --lf
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
run-last-failure: rerun last 2 failures run-last-failure: rerun last 2 failures
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 50 items collected 50 items
@ -122,7 +122,7 @@ of ``FF`` and dots)::
$ pytest --ff $ pytest --ff
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
run-last-failure: rerun last 2 failures first run-last-failure: rerun last 2 failures first
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 50 items collected 50 items
@ -227,7 +227,7 @@ You can always peek at the content of the cache using the
$ py.test --cache-show $ py.test --cache-show
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
cachedir: $REGENDOC_TMPDIR/.cache cachedir: $REGENDOC_TMPDIR/.cache
------------------------------- cache values ------------------------------- ------------------------------- cache values -------------------------------
@ -246,7 +246,7 @@ by adding the ``--cache-clear`` option like this::
pytest --cache-clear pytest --cache-clear
This is recommended for invocations from Continous Integration This is recommended for invocations from Continuous Integration
servers where isolation and correctness is more important servers where isolation and correctness is more important
than speed. than speed.

View File

@ -64,7 +64,7 @@ of the failing function and hide the other one::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items

View File

@ -303,7 +303,7 @@ texinfo_documents = [
('Holger Krekel@*Benjamin Peterson@*Ronny Pfannschmidt@*' ('Holger Krekel@*Benjamin Peterson@*Ronny Pfannschmidt@*'
'Floris Bruynooghe@*others'), 'Floris Bruynooghe@*others'),
'pytest', 'pytest',
'simple powerful testing with Pytho', 'simple powerful testing with Python',
'Programming', 'Programming',
1), 1),
] ]

View File

@ -62,7 +62,7 @@ then you can just invoke ``pytest`` without command line options::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 1 items collected 1 items

View File

@ -31,7 +31,7 @@ You can then restrict a test run to only run tests marked with ``webtest``::
$ pytest -v -m webtest $ pytest -v -m webtest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -45,7 +45,7 @@ Or the inverse, running all tests except the webtest ones::
$ pytest -v -m "not webtest" $ pytest -v -m "not webtest"
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -66,7 +66,7 @@ tests based on their module, class, method, or function name::
$ pytest -v test_server.py::TestClass::test_method $ pytest -v test_server.py::TestClass::test_method
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 5 items collecting ... collected 5 items
@ -79,7 +79,7 @@ You can also select on the class::
$ pytest -v test_server.py::TestClass $ pytest -v test_server.py::TestClass
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -92,7 +92,7 @@ Or select multiple nodes::
$ pytest -v test_server.py::TestClass test_server.py::test_send_http $ pytest -v test_server.py::TestClass test_server.py::test_send_http
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items collecting ... collected 8 items
@ -130,7 +130,7 @@ select tests based on their names::
$ pytest -v -k http # running with the above defined example module $ pytest -v -k http # running with the above defined example module
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -144,7 +144,7 @@ And you can also run all tests except the ones that match the keyword::
$ pytest -k "not send_http" -v $ pytest -k "not send_http" -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -160,7 +160,7 @@ Or to select "http" and "quick" tests::
$ pytest -k "http or quick" -v $ pytest -k "http or quick" -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -205,7 +205,7 @@ You can ask which markers exist for your test suite - the list includes our just
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html @pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html @pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples. @pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@ -352,7 +352,7 @@ the test needs::
$ pytest -E stage2 $ pytest -E stage2
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -364,7 +364,7 @@ and here is one that specifies exactly the environment needed::
$ pytest -E stage1 $ pytest -E stage1
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -381,7 +381,7 @@ The ``--markers`` option always gives you a list of available markers::
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html @pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html @pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples. @pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@ -450,7 +450,7 @@ for your particular platform, you could use the following plugin::
import sys import sys
import pytest import pytest
ALL = set("darwin linux2 win32".split()) ALL = set("darwin linux win32".split())
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
if isinstance(item, item.Function): if isinstance(item, item.Function):
@ -470,7 +470,7 @@ Let's do a little test file to show how this looks like::
def test_if_apple_is_evil(): def test_if_apple_is_evil():
pass pass
@pytest.mark.linux2 @pytest.mark.linux
def test_if_linux_works(): def test_if_linux_works():
pass pass
@ -481,32 +481,32 @@ Let's do a little test file to show how this looks like::
def test_runs_everywhere(): def test_runs_everywhere():
pass pass
then you will see two test skipped and two executed tests as expected:: then you will see two tests skipped and two executed tests as expected::
$ pytest -rs # this option reports skip reasons $ pytest -rs # this option reports skip reasons
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
test_plat.py sss. test_plat.py s.s.
======= short test summary info ======== ======= short test summary info ========
SKIP [3] $REGENDOC_TMPDIR/conftest.py:12: cannot run on platform linux SKIP [2] $REGENDOC_TMPDIR/conftest.py:12: cannot run on platform linux
======= 1 passed, 3 skipped in 0.12 seconds ======== ======= 2 passed, 2 skipped in 0.12 seconds ========
Note that if you specify a platform via the marker-command line option like this:: Note that if you specify a platform via the marker-command line option like this::
$ pytest -m linux2 $ pytest -m linux
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
test_plat.py s test_plat.py .
======= 3 tests deselected ======== ======= 3 tests deselected ========
======= 1 skipped, 3 deselected in 0.12 seconds ======== ======= 1 passed, 3 deselected in 0.12 seconds ========
then the unmarked-tests will not be run. It is thus a way to restrict the run to the specific tests. then the unmarked-tests will not be run. It is thus a way to restrict the run to the specific tests.
@ -551,7 +551,7 @@ We can now use the ``-m option`` to select one set::
$ pytest -m interface --tb=short $ pytest -m interface --tb=short
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
@ -573,7 +573,7 @@ or to select both "event" and "interface" tests::
$ pytest -m "interface or event" --tb=short $ pytest -m "interface or event" --tb=short
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items

View File

@ -27,7 +27,7 @@ now execute the test specification::
nonpython $ pytest test_simple.yml nonpython $ pytest test_simple.yml
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/nonpython, inifile: rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collected 2 items collected 2 items
@ -59,7 +59,7 @@ consulted when reporting in ``verbose`` mode::
nonpython $ pytest -v nonpython $ pytest -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR/nonpython, inifile: rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collecting ... collected 2 items collecting ... collected 2 items
@ -81,7 +81,7 @@ interesting to just look at the collection tree::
nonpython $ pytest --collect-only nonpython $ pytest --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/nonpython, inifile: rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collected 2 items collected 2 items
<YamlFile 'test_simple.yml'> <YamlFile 'test_simple.yml'>

View File

@ -130,7 +130,7 @@ objects, they are still using the default pytest representation::
$ pytest test_time.py --collect-only $ pytest test_time.py --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 6 items collected 6 items
<Module 'test_time.py'> <Module 'test_time.py'>
@ -181,7 +181,7 @@ this is a fully self-contained example which you can run with::
$ pytest test_scenarios.py $ pytest test_scenarios.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
@ -194,7 +194,7 @@ If you just collect tests you'll also nicely see 'advanced' and 'basic' as varia
$ pytest --collect-only test_scenarios.py $ pytest --collect-only test_scenarios.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
<Module 'test_scenarios.py'> <Module 'test_scenarios.py'>
@ -259,7 +259,7 @@ Let's first see how it looks like at collection time::
$ pytest test_backends.py --collect-only $ pytest test_backends.py --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
<Module 'test_backends.py'> <Module 'test_backends.py'>
@ -320,7 +320,7 @@ The result of this test will be successful::
$ pytest test_indirect_list.py --collect-only $ pytest test_indirect_list.py --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
<Module 'test_indirect_list.py'> <Module 'test_indirect_list.py'>
@ -397,10 +397,12 @@ is to be run with different sets of arguments for its three arguments:
Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize):: Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize)::
. $ pytest -rs -q multipython.py . $ pytest -rs -q multipython.py
sssssssssssssss.........sss.........sss......... sssssssssssssssssssssssssssssssssssssssssssss...
======= short test summary info ======== ======= short test summary info ========
SKIP [21] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python2.6' not found SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python2.6' not found
27 passed, 21 skipped in 0.12 seconds SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python3.4' not found
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python2.7' not found
3 passed, 45 skipped in 0.12 seconds
Indirect parametrization of optional implementations/imports Indirect parametrization of optional implementations/imports
-------------------------------------------------------------------- --------------------------------------------------------------------
@ -447,7 +449,7 @@ If you run this with reporting for skips enabled::
$ pytest -rs test_module.py $ pytest -rs test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items

View File

@ -95,7 +95,7 @@ the :confval:`python_files`, :confval:`python_classes` and
:confval:`python_functions` configuration options. Example:: :confval:`python_functions` configuration options. Example::
# content of pytest.ini # content of pytest.ini
# can also be defined in in tox.ini or setup.cfg file, although the section # can also be defined in tox.ini or setup.cfg file, although the section
# name in setup.cfg files should be "tool:pytest" # name in setup.cfg files should be "tool:pytest"
[pytest] [pytest]
python_files=check_*.py python_files=check_*.py
@ -117,7 +117,7 @@ then the test collection looks like this::
$ pytest --collect-only $ pytest --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 2 items collected 2 items
<Module 'check_myapp.py'> <Module 'check_myapp.py'>
@ -163,7 +163,7 @@ You can always peek at the collection tree without running tests like this::
. $ pytest --collect-only pythoncollection.py . $ pytest --collect-only pythoncollection.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 3 items collected 3 items
<Module 'CWD/pythoncollection.py'> <Module 'CWD/pythoncollection.py'>
@ -230,7 +230,7 @@ will be left out::
$ pytest --collect-only $ pytest --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 0 items collected 0 items

View File

@ -11,7 +11,7 @@ get on the terminal - we are working on that)::
assertion $ pytest failure_demo.py assertion $ pytest failure_demo.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/assertion, inifile: rootdir: $REGENDOC_TMPDIR/assertion, inifile:
collected 42 items collected 42 items

View File

@ -113,7 +113,7 @@ directory with the above conftest.py::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items collected 0 items
@ -164,7 +164,7 @@ and when running it will see a skipped "slow" test::
$ pytest -rs # "-rs" means report details on the little 's' $ pytest -rs # "-rs" means report details on the little 's'
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -178,7 +178,7 @@ Or run it including the ``slow`` marked test::
$ pytest --runslow $ pytest --runslow
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -302,7 +302,7 @@ which will add the string to the test header accordingly::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
project deps: mylib-1.1 project deps: mylib-1.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items collected 0 items
@ -327,7 +327,7 @@ which will add info only when run with "--v"::
$ pytest -v $ pytest -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
info1: did you know that ... info1: did you know that ...
did you? did you?
@ -340,7 +340,7 @@ and nothing when run plainly::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items collected 0 items
@ -374,7 +374,7 @@ Now we can profile which test functions execute the slowest::
$ pytest --durations=3 $ pytest --durations=3
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items
@ -440,7 +440,7 @@ If we run this::
$ pytest -rx $ pytest -rx
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
@ -476,7 +476,7 @@ concept. It's however recommended to have explicit fixture references in your
tests or test classes rather than relying on implicitly executing tests or test classes rather than relying on implicitly executing
setup/teardown functions, especially if they are far away from the actual tests. setup/teardown functions, especially if they are far away from the actual tests.
Here is a an example for making a ``db`` fixture available in a directory: Here is an example for making a ``db`` fixture available in a directory:
.. code-block:: python .. code-block:: python
@ -519,7 +519,7 @@ We can run this::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 7 items collected 7 items
@ -585,7 +585,7 @@ environment you can implement a hook that gets called when the test
"report" object is about to be created. Here we write out all failing "report" object is about to be created. Here we write out all failing
test calls and also access a fixture (if it was used by the test) in test calls and also access a fixture (if it was used by the test) in
case you want to query/look at it during your post processing. In our case you want to query/look at it during your post processing. In our
case we just write some informations out to a ``failures`` file: case we just write some information out to a ``failures`` file:
.. code-block:: python .. code-block:: python
@ -627,7 +627,7 @@ and run them::
$ pytest test_module.py $ pytest test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -678,7 +678,7 @@ here is a little example implemented via a local plugin:
outcome = yield outcome = yield
rep = outcome.get_result() rep = outcome.get_result()
# set an report attribute for each phase of a call, which can # set a report attribute for each phase of a call, which can
# be "setup", "call", "teardown" # be "setup", "call", "teardown"
setattr(item, "rep_" + rep.when, rep) setattr(item, "rep_" + rep.when, rep)
@ -721,7 +721,7 @@ and run it::
$ pytest -s test_module.py $ pytest -s test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items

View File

@ -66,14 +66,6 @@ This completely avoids previous issues of confusing assertion-reporting.
It also means, that you can use Python's ``-O`` optimization without losing It also means, that you can use Python's ``-O`` optimization without losing
assertions in test modules. assertions in test modules.
``pytest`` contains a second, mostly obsolete, assert debugging technique
invoked via ``--assert=reinterpret``: When an ``assert`` statement fails, ``pytest`` re-interprets
the expression part to show intermediate values. This technique suffers
from a caveat that the rewriting does not: If your expression has side
effects (better to avoid them anyway!) the intermediate values may not
be the same, confusing the reinterpreter and obfuscating the initial
error (this is also explained at the command line if it happens).
You can also turn off all assertion interaction using the You can also turn off all assertion interaction using the
``--assert=plain`` option. ``--assert=plain`` option.

View File

@ -11,7 +11,7 @@ pytest fixtures: explicit, modular, scalable
.. _`xUnit`: http://en.wikipedia.org/wiki/XUnit .. _`xUnit`: http://en.wikipedia.org/wiki/XUnit
.. _`purpose of test fixtures`: http://en.wikipedia.org/wiki/Test_fixture#Software .. _`purpose of test fixtures`: http://en.wikipedia.org/wiki/Test_fixture#Software
.. _`Dependency injection`: http://en.wikipedia.org/wiki/Dependency_injection#Definition .. _`Dependency injection`: http://en.wikipedia.org/wiki/Dependency_injection
The `purpose of test fixtures`_ is to provide a fixed baseline The `purpose of test fixtures`_ is to provide a fixed baseline
upon which tests can reliably and repeatedly execute. pytest fixtures upon which tests can reliably and repeatedly execute. pytest fixtures
@ -70,7 +70,7 @@ marked ``smtp`` fixture function. Running the test looks like this::
$ pytest test_smtpsimple.py $ pytest test_smtpsimple.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -188,7 +188,7 @@ inspect what is going on and can now run the tests::
$ pytest test_module.py $ pytest test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -520,7 +520,7 @@ Running the above tests results in the following test IDs being used::
$ pytest --collect-only $ pytest --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 11 items collected 11 items
<Module 'test_anothersmtp.py'> <Module 'test_anothersmtp.py'>
@ -573,7 +573,7 @@ Here we declare an ``app`` fixture which receives the previously defined
$ pytest -v test_appsetup.py $ pytest -v test_appsetup.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items collecting ... collected 2 items
@ -642,7 +642,7 @@ Let's run the tests in verbose mode and with looking at the print-output::
$ pytest -v -s test_module.py $ pytest -v -s test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items collecting ... collected 8 items

View File

@ -97,7 +97,7 @@ sets. pytest-2.3 introduces a decorator for use on the factory itself::
... # use request.param ... # use request.param
Here the factory will be invoked twice (with the respective "mysql" Here the factory will be invoked twice (with the respective "mysql"
and "pg" values set as ``request.param`` attributes) and and all of and "pg" values set as ``request.param`` attributes) and all of
the tests requiring "db" will run twice as well. The "mysql" and the tests requiring "db" will run twice as well. The "mysql" and
"pg" values will also be used for reporting the test-invocation variants. "pg" values will also be used for reporting the test-invocation variants.

View File

@ -26,7 +26,7 @@ Installation::
To check your installation has installed the correct version:: To check your installation has installed the correct version::
$ pytest --version $ pytest --version
This is pytest version 3.0.5, imported from $PYTHON_PREFIX/lib/python3.5/site-packages/pytest.py This is pytest version 3.0.6, imported from $PYTHON_PREFIX/lib/python3.5/site-packages/pytest.py
.. _`simpletest`: .. _`simpletest`:
@ -46,7 +46,7 @@ That's it. You can execute the test function now::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items

View File

@ -147,7 +147,7 @@ dependencies are isolated from the system Python installation.
If you frequently release code and want to make sure that your actual If you frequently release code and want to make sure that your actual
package passes all tests you may want to look into `tox`_, the package passes all tests you may want to look into `tox`_, the
virtualenv test automation tool and its `pytest support virtualenv test automation tool and its `pytest support
<http://testrun.org/tox/latest/example/pytest.html>`_. <https://tox.readthedocs.io/en/latest/example/pytest.html>`_.
Tox helps you to setup virtualenv environments with pre-defined Tox helps you to setup virtualenv environments with pre-defined
dependencies and then executing a pre-configured test command with dependencies and then executing a pre-configured test command with
options. It will run tests against the installed package and not options. It will run tests against the installed package and not

View File

@ -25,7 +25,7 @@ To execute it::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items

View File

@ -35,7 +35,7 @@ patch this function before calling into a function which uses it::
assert x == '/abc/.ssh' assert x == '/abc/.ssh'
Here our test function monkeypatches ``os.path.expanduser`` and Here our test function monkeypatches ``os.path.expanduser`` and
then calls into an function that calls it. After the test function then calls into a function that calls it. After the test function
finishes the ``os.path.expanduser`` modification will be undone. finishes the ``os.path.expanduser`` modification will be undone.
example: preventing "requests" from remote operations example: preventing "requests" from remote operations
@ -60,7 +60,7 @@ so that any attempts within tests to create http requests will fail.
Be advised that it is not recommended to patch builtin functions such as ``open``, Be advised that it is not recommended to patch builtin functions such as ``open``,
``compile``, etc., because it might break pytest's internals. If that's ``compile``, etc., because it might break pytest's internals. If that's
unavoidable, passing ``--tb=native``, ``--assert=plain`` and ``--capture=no`` might unavoidable, passing ``--tb=native``, ``--assert=plain`` and ``--capture=no`` might
help althought there's no guarantee. help although there's no guarantee.
Method reference of the monkeypatch fixture Method reference of the monkeypatch fixture

View File

@ -55,7 +55,7 @@ them in turn::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items
@ -103,7 +103,7 @@ Let's run this::
$ pytest $ pytest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items

View File

@ -58,7 +58,7 @@ Here are some examples of projects using ``pytest`` (please send notes via :ref:
* `katcp <https://bitbucket.org/hodgestar/katcp>`_ Telescope communication protocol over Twisted * `katcp <https://bitbucket.org/hodgestar/katcp>`_ Telescope communication protocol over Twisted
* `kss plugin timer <http://pypi.python.org/pypi/kss.plugin.timer>`_ * `kss plugin timer <http://pypi.python.org/pypi/kss.plugin.timer>`_
* `pyudev <https://pyudev.readthedocs.io/en/latest/tests/plugins.html>`_ a pure Python binding to the Linux library libudev * `pyudev <https://pyudev.readthedocs.io/en/latest/tests/plugins.html>`_ a pure Python binding to the Linux library libudev
* `pytest-localserver <https://bitbucket.org/basti/pytest-localserver/>`_ a plugin for pytest that provides a httpserver and smtpserver * `pytest-localserver <https://bitbucket.org/basti/pytest-localserver/>`_ a plugin for pytest that provides an httpserver and smtpserver
* `pytest-monkeyplus <http://pypi.python.org/pypi/pytest-monkeyplus/>`_ a plugin that extends monkeypatch * `pytest-monkeyplus <http://pypi.python.org/pypi/pytest-monkeyplus/>`_ a plugin that extends monkeypatch
These projects help integrate ``pytest`` into other Python frameworks: These projects help integrate ``pytest`` into other Python frameworks:

View File

@ -2,7 +2,7 @@
.. _skipping: .. _skipping:
Skip and xfail: dealing with tests that can not succeed Skip and xfail: dealing with tests that cannot succeed
===================================================================== =====================================================================
If you have test functions that cannot be run on certain platforms If you have test functions that cannot be run on certain platforms
@ -224,7 +224,7 @@ Running it with the report-on-xfail option gives this output::
example $ pytest -rx xfail_demo.py example $ pytest -rx xfail_demo.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/example, inifile: rootdir: $REGENDOC_TMPDIR/example, inifile:
collected 7 items collected 7 items

View File

@ -71,7 +71,7 @@ you can ad-hoc distribute your tests by typing::
pytest -d --tx ssh=myhostpopen --rsyncdir mypkg mypkg pytest -d --tx ssh=myhostpopen --rsyncdir mypkg mypkg
This will synchronize your ``mypkg`` package directory This will synchronize your ``mypkg`` package directory
to an remote ssh account and then locally collect tests to a remote ssh account and then locally collect tests
and send them to remote places for execution. and send them to remote places for execution.
You can specify multiple ``--rsyncdir`` directories You can specify multiple ``--rsyncdir`` directories

View File

@ -29,7 +29,7 @@ Running this would result in a passed test except for the last
$ pytest test_tmpdir.py $ pytest test_tmpdir.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items

View File

@ -17,6 +17,14 @@ run using ``pytest``. We assume here that you are familiar with writing
``unittest.TestCase`` style tests and rather focus on ``unittest.TestCase`` style tests and rather focus on
integration aspects. integration aspects.
Note that this is meant as a provisional way of running your test code
until you fully convert to pytest-style tests. To fully take advantage of
:ref:`fixtures <fixture>`, :ref:`parametrization <parametrize>` and
:ref:`hooks <writing-plugins>` you should convert (tools like `unittest2pytest
<https://pypi.python.org/pypi/unittest2pytest/>`__ are helpful).
Also, not all 3rd party pluging are expected to work best with
``unittest.TestCase`` style tests.
Usage Usage
------------------------------------------------------------------- -------------------------------------------------------------------
@ -100,7 +108,7 @@ the ``self.db`` values in the traceback::
$ pytest test_unittest_db.py $ pytest test_unittest_db.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -191,12 +199,3 @@ was executed ahead of the ``test_method``.
pytest fixtures into unittest suites. And of course you can also start pytest fixtures into unittest suites. And of course you can also start
to selectively leave away the ``unittest.TestCase`` subclassing, use to selectively leave away the ``unittest.TestCase`` subclassing, use
plain asserts and get the unlimited pytest feature set. plain asserts and get the unlimited pytest feature set.
Converting from unittest to pytest
---------------------------------------
If you want to convert your unittest testcases to pytest, there are
some helpers like `unittest2pytest
<https://pypi.python.org/pypi/unittest2pytest/>`__, which uses lib2to3
and introspection for the transformation.

View File

@ -49,7 +49,7 @@ Several test run options::
# will select TestMyClass.test_something # will select TestMyClass.test_something
# but not TestMyClass.test_method_simple # but not TestMyClass.test_method_simple
pytest test_mod.py::test_func # only run tests that match the "node ID", pytest test_mod.py::test_func # only run tests that match the "node ID",
# e.g "test_mod.py::test_func" will select # e.g. "test_mod.py::test_func" will select
# only test_func in test_mod.py # only test_func in test_mod.py
pytest test_mod.py::TestClass::test_method # run a single method in pytest test_mod.py::TestClass::test_method # run a single method in
# a single class # a single class
@ -76,7 +76,7 @@ Examples for modifying traceback printing::
The ``--full-trace`` causes very long traces to be printed on error (longer The ``--full-trace`` causes very long traces to be printed on error (longer
than ``--tb=long``). It also ensures that a stack trace is printed on than ``--tb=long``). It also ensures that a stack trace is printed on
**KeyboardInterrrupt** (Ctrl+C). **KeyboardInterrupt** (Ctrl+C).
This is very useful if the tests are taking too long and you interrupt them This is very useful if the tests are taking too long and you interrupt them
with Ctrl+C to find out where the tests are *hanging*. By default no output with Ctrl+C to find out where the tests are *hanging*. By default no output
will be shown (because KeyboardInterrupt is caught by pytest). By using this will be shown (because KeyboardInterrupt is caught by pytest). By using this

View File

@ -172,7 +172,7 @@ If a package is installed this way, ``pytest`` will load
.. note:: .. note::
Make sure to include ``Framework :: Pytest`` in your list of Make sure to include ``Framework :: Pytest`` in your list of
`PyPI classifiers <https://python-packaging-user-guide.readthedocs.io/en/latest/distributing/#classifiers>`_ `PyPI classifiers <https://python-packaging-user-guide.readthedocs.io/distributing/#classifiers>`_
to make it easy for users to find your plugin. to make it easy for users to find your plugin.
@ -250,8 +250,8 @@ which will import the specified module as a ``pytest`` plugin.
Plugins imported like this will automatically be marked to require Plugins imported like this will automatically be marked to require
assertion rewriting using the :func:`pytest.register_assert_rewrite` assertion rewriting using the :func:`pytest.register_assert_rewrite`
mechanism. However for this to have any effect the module must not be mechanism. However for this to have any effect the module must not be
imported already, it it was already imported at the time the imported already; if it was already imported at the time the
``pytest_plugins`` statement is processed a warning will result and ``pytest_plugins`` statement is processed, a warning will result and
assertions inside the plugin will not be re-written. To fix this you assertions inside the plugin will not be re-written. To fix this you
can either call :func:`pytest.register_assert_rewrite` yourself before can either call :func:`pytest.register_assert_rewrite` yourself before
the module is imported, or you can arrange the code to delay the the module is imported, or you can arrange the code to delay the

View File

@ -9,5 +9,8 @@ upload-dir = doc/en/build/html
[bdist_wheel] [bdist_wheel]
universal = 1 universal = 1
[metadata]
license_file = LICENSE
[devpi:upload] [devpi:upload]
formats = sdist.tgz,bdist_wheel formats = sdist.tgz,bdist_wheel

View File

@ -13,7 +13,7 @@ classifiers = ['Development Status :: 6 - Mature',
'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries',
'Topic :: Utilities'] + [ 'Topic :: Utilities'] + [
('Programming Language :: Python :: %s' % x) for x in ('Programming Language :: Python :: %s' % x) for x in
'2 2.6 2.7 3 3.3 3.4 3.5'.split()] '2 2.6 2.7 3 3.3 3.4 3.5 3.6'.split()]
with open('README.rst') as fd: with open('README.rst') as fd:
long_description = fd.read() long_description = fd.read()
@ -68,7 +68,6 @@ def main():
license='MIT license', license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
author='Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others', author='Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others',
author_email='holger at merlinux.eu',
entry_points={'console_scripts': entry_points={'console_scripts':
['pytest=pytest:main', 'py.test=pytest:main']}, ['pytest=pytest:main', 'py.test=pytest:main']},
classifiers=classifiers, classifiers=classifiers,

View File

@ -59,6 +59,23 @@ class TestImportHookInstallation:
assert 0 assert 0
result.stdout.fnmatch_lines([expected]) result.stdout.fnmatch_lines([expected])
def test_rewrite_assertions_pytester_plugin(self, testdir):
"""
Assertions in the pytester plugin must also benefit from assertion
rewriting (#1920).
"""
testdir.makepyfile("""
pytest_plugins = ['pytester']
def test_dummy_failure(testdir): # how meta!
testdir.makepyfile('def test(): assert 0')
r = testdir.inline_run()
r.assertoutcome(passed=1)
""")
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines([
'*assert 1 == 0*',
])
@pytest.mark.parametrize('mode', ['plain', 'rewrite']) @pytest.mark.parametrize('mode', ['plain', 'rewrite'])
def test_pytest_plugins_rewrite(self, testdir, mode): def test_pytest_plugins_rewrite(self, testdir, mode):
contents = { contents = {

View File

@ -682,7 +682,7 @@ def test_rewritten():
hook.mark_rewrite('test_remember_rewritten_modules') hook.mark_rewrite('test_remember_rewritten_modules')
assert warnings == [] assert warnings == []
def test_rewrite_warning_using_pytest_plugins(self, testdir, monkeypatch): def test_rewrite_warning_using_pytest_plugins(self, testdir):
testdir.makepyfile(**{ testdir.makepyfile(**{
'conftest.py': "pytest_plugins = ['core', 'gui', 'sci']", 'conftest.py': "pytest_plugins = ['core', 'gui', 'sci']",
'core.py': "", 'core.py': "",
@ -695,6 +695,22 @@ def test_rewritten():
result.stdout.fnmatch_lines(['*= 1 passed in *=*']) result.stdout.fnmatch_lines(['*= 1 passed in *=*'])
assert 'pytest-warning summary' not in result.stdout.str() assert 'pytest-warning summary' not in result.stdout.str()
def test_rewrite_warning_using_pytest_plugins_env_var(self, testdir, monkeypatch):
monkeypatch.setenv('PYTEST_PLUGINS', 'plugin')
testdir.makepyfile(**{
'plugin.py': "",
'test_rewrite_warning_using_pytest_plugins_env_var.py': """
import plugin
pytest_plugins = ['plugin']
def test():
pass
""",
})
testdir.chdir()
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines(['*= 1 passed in *=*'])
assert 'pytest-warning summary' not in result.stdout.str()
class TestAssertionRewriteHookDetails(object): class TestAssertionRewriteHookDetails(object):
def test_loader_is_package_false_for_module(self, testdir): def test_loader_is_package_false_for_module(self, testdir):

View File

@ -587,6 +587,21 @@ def test_load_initial_conftest_last_ordering(testdir):
assert [x.function.__module__ for x in l] == expected assert [x.function.__module__ for x in l] == expected
def test_get_plugin_specs_as_list():
from _pytest.config import _get_plugin_specs_as_list
with pytest.raises(pytest.UsageError):
_get_plugin_specs_as_list(set(['foo']))
with pytest.raises(pytest.UsageError):
_get_plugin_specs_as_list(dict())
assert _get_plugin_specs_as_list(None) == []
assert _get_plugin_specs_as_list('') == []
assert _get_plugin_specs_as_list('foo') == ['foo']
assert _get_plugin_specs_as_list('foo,bar') == ['foo', 'bar']
assert _get_plugin_specs_as_list(['foo', 'bar']) == ['foo', 'bar']
assert _get_plugin_specs_as_list(('foo', 'bar')) == ['foo', 'bar']
class TestWarning: class TestWarning:
def test_warn_config(self, testdir): def test_warn_config(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""

View File

@ -7,17 +7,13 @@ from _pytest.monkeypatch import MonkeyPatch
@pytest.fixture @pytest.fixture
def mp(request): def mp():
cwd = os.getcwd() cwd = os.getcwd()
sys_path = list(sys.path) sys_path = list(sys.path)
yield MonkeyPatch()
def cleanup():
sys.path[:] = sys_path sys.path[:] = sys_path
os.chdir(cwd) os.chdir(cwd)
request.addfinalizer(cleanup)
return MonkeyPatch()
def test_setattr(): def test_setattr():
class A: class A:
@ -329,5 +325,3 @@ def test_issue1338_name_resolving():
monkeypatch.delattr('requests.sessions.Session.request') monkeypatch.delattr('requests.sessions.Session.request')
finally: finally:
monkeypatch.undo() monkeypatch.undo()

View File

@ -124,3 +124,10 @@ def test_inline_run_clean_modules(testdir):
test_mod.write("def test_foo(): assert False") test_mod.write("def test_foo(): assert False")
result2 = testdir.inline_run(str(test_mod)) result2 = testdir.inline_run(str(test_mod))
assert result2.ret == EXIT_TESTSFAILED assert result2.ret == EXIT_TESTSFAILED
def test_assert_outcomes_after_pytest_erro(testdir):
testdir.makepyfile("def test_foo(): assert True")
result = testdir.runpytest('--unexpected-argument')
with pytest.raises(ValueError, message="Pytest terminal report not found"):
result.assert_outcomes(passed=0)

View File

@ -10,6 +10,7 @@ envlist=
py34 py34
py35 py35
py36 py36
py37
pypy pypy
{py27,py35}-{pexpect,xdist,trial} {py27,py35}-{pexpect,xdist,trial}
py27-nobyte py27-nobyte
@ -118,11 +119,13 @@ commands=
basepython = python basepython = python
usedevelop=True usedevelop=True
skipsdist=True skipsdist=True
# ensure the given pyargs cant mean anytrhing else
changedir=doc/
deps= deps=
PyYAML PyYAML
commands= commands=
pytest -rfsxX doc/en pytest -rfsxX en
pytest --doctest-modules {toxinidir}/_pytest pytest --doctest-modules --pyargs _pytest
[testenv:regen] [testenv:regen]
changedir=doc/en changedir=doc/en