replace py.test module references with pytest
The only remaining 'py.test' references are: * those referring to the 'py.test' executable * those in code explicitly testing py.test/pytest module compatibility * those in old CHANGES documentation * those in documentation generated based on external data * those in seemingly unfinished & unmaintained Japanese documentation Minor stylistic changes and typo corrections made to documentation next to several applied py.test --> pytest content changes.
This commit is contained in:
parent
83620ced2e
commit
9fb2079458
40
ISSUES.txt
40
ISSUES.txt
|
@ -122,8 +122,8 @@ customize test function collection
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
tags: feature
|
tags: feature
|
||||||
|
|
||||||
- introduce py.test.mark.nocollect for not considering a function for
|
- introduce pytest.mark.nocollect for not considering a function for
|
||||||
test collection at all. maybe also introduce a py.test.mark.test to
|
test collection at all. maybe also introduce a pytest.mark.test to
|
||||||
explicitely mark a function to become a tested one. Lookup JUnit ways
|
explicitely mark a function to become a tested one. Lookup JUnit ways
|
||||||
of tagging tests.
|
of tagging tests.
|
||||||
|
|
||||||
|
@ -135,18 +135,18 @@ in addition to the imperative pytest.importorskip also introduce
|
||||||
a pytest.mark.importorskip so that the test count is more correct.
|
a pytest.mark.importorskip so that the test count is more correct.
|
||||||
|
|
||||||
|
|
||||||
introduce py.test.mark.platform
|
introduce pytest.mark.platform
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
tags: feature
|
tags: feature
|
||||||
|
|
||||||
Introduce nice-to-spell platform-skipping, examples:
|
Introduce nice-to-spell platform-skipping, examples:
|
||||||
|
|
||||||
@py.test.mark.platform("python3")
|
@pytest.mark.platform("python3")
|
||||||
@py.test.mark.platform("not python3")
|
@pytest.mark.platform("not python3")
|
||||||
@py.test.mark.platform("win32 and not python3")
|
@pytest.mark.platform("win32 and not python3")
|
||||||
@py.test.mark.platform("darwin")
|
@pytest.mark.platform("darwin")
|
||||||
@py.test.mark.platform("not (jython and win32)")
|
@pytest.mark.platform("not (jython and win32)")
|
||||||
@py.test.mark.platform("not (jython and win32)", xfail=True)
|
@pytest.mark.platform("not (jython and win32)", xfail=True)
|
||||||
|
|
||||||
etc. Idea is to allow Python expressions which can operate
|
etc. Idea is to allow Python expressions which can operate
|
||||||
on common spellings for operating systems and python
|
on common spellings for operating systems and python
|
||||||
|
@ -181,8 +181,8 @@ tags: feature
|
||||||
allow to name conftest.py files (in sub directories) that should
|
allow to name conftest.py files (in sub directories) that should
|
||||||
be imported early, as to include command line options.
|
be imported early, as to include command line options.
|
||||||
|
|
||||||
improve central py.test ini file
|
improve central pytest ini file
|
||||||
----------------------------------
|
-------------------------------
|
||||||
tags: feature
|
tags: feature
|
||||||
|
|
||||||
introduce more declarative configuration options:
|
introduce more declarative configuration options:
|
||||||
|
@ -196,7 +196,7 @@ new documentation
|
||||||
----------------------------------
|
----------------------------------
|
||||||
tags: feature
|
tags: feature
|
||||||
|
|
||||||
- logo py.test
|
- logo pytest
|
||||||
- examples for unittest or functional testing
|
- examples for unittest or functional testing
|
||||||
- resource management for functional testing
|
- resource management for functional testing
|
||||||
- patterns: page object
|
- patterns: page object
|
||||||
|
@ -205,17 +205,17 @@ have imported module mismatch honour relative paths
|
||||||
--------------------------------------------------------
|
--------------------------------------------------------
|
||||||
tags: bug
|
tags: bug
|
||||||
|
|
||||||
With 1.1.1 py.test fails at least on windows if an import
|
With 1.1.1 pytest fails at least on windows if an import
|
||||||
is relative and compared against an absolute conftest.py
|
is relative and compared against an absolute conftest.py
|
||||||
path. Normalize.
|
path. Normalize.
|
||||||
|
|
||||||
consider globals: py.test.ensuretemp and config
|
consider globals: pytest.ensuretemp and config
|
||||||
--------------------------------------------------------------
|
--------------------------------------------------------------
|
||||||
tags: experimental-wish
|
tags: experimental-wish
|
||||||
|
|
||||||
consider deprecating py.test.ensuretemp and py.test.config
|
consider deprecating pytest.ensuretemp and pytest.config
|
||||||
to further reduce py.test globality. Also consider
|
to further reduce pytest globality. Also consider
|
||||||
having py.test.config and ensuretemp coming from
|
having pytest.config and ensuretemp coming from
|
||||||
a plugin rather than being there from the start.
|
a plugin rather than being there from the start.
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ consider pytest_addsyspath hook
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
tags: wish
|
tags: wish
|
||||||
|
|
||||||
py.test could call a new pytest_addsyspath() in order to systematically
|
pytest could call a new pytest_addsyspath() in order to systematically
|
||||||
allow manipulation of sys.path and to inhibit it via --no-addsyspath
|
allow manipulation of sys.path and to inhibit it via --no-addsyspath
|
||||||
in order to more easily run against installed packages.
|
in order to more easily run against installed packages.
|
||||||
|
|
||||||
|
@ -232,11 +232,11 @@ and pytest_configure.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deprecate global py.test.config usage
|
deprecate global pytest.config usage
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
tags: feature
|
tags: feature
|
||||||
|
|
||||||
py.test.ensuretemp and py.test.config are probably the last
|
pytest.ensuretemp and pytest.config are probably the last
|
||||||
objects containing global state. Often using them is not
|
objects containing global state. Often using them is not
|
||||||
neccessary. This is about trying to get rid of them, i.e.
|
neccessary. This is about trying to get rid of them, i.e.
|
||||||
deprecating them and checking with PyPy's usages as well
|
deprecating them and checking with PyPy's usages as well
|
||||||
|
|
|
@ -5,7 +5,7 @@ Changelog: http://pytest.org/latest/changelog.html
|
||||||
|
|
||||||
Issues: https://bitbucket.org/hpk42/pytest/issues?status=open
|
Issues: https://bitbucket.org/hpk42/pytest/issues?status=open
|
||||||
|
|
||||||
The ``py.test`` testing tool makes it easy to write small tests, yet
|
The ``pytest`` testing tool makes it easy to write small tests, yet
|
||||||
scales to support complex functional testing. It provides
|
scales to support complex functional testing. It provides
|
||||||
|
|
||||||
- `auto-discovery
|
- `auto-discovery
|
||||||
|
@ -14,7 +14,7 @@ scales to support complex functional testing. It provides
|
||||||
- detailed info on failing `assert statements <http://pytest.org/latest/assert.html>`_ (no need to remember ``self.assert*`` names)
|
- detailed info on failing `assert statements <http://pytest.org/latest/assert.html>`_ (no need to remember ``self.assert*`` names)
|
||||||
- `modular fixtures <http://pytest.org/latest/fixture.html>`_ for
|
- `modular fixtures <http://pytest.org/latest/fixture.html>`_ for
|
||||||
managing small or parametrized long-lived test resources.
|
managing small or parametrized long-lived test resources.
|
||||||
- multi-paradigm support: you can use ``py.test`` to run test suites based
|
- multi-paradigm support: you can use ``pytest`` to run test suites based
|
||||||
on `unittest <http://pytest.org/latest/unittest.html>`_ (or trial),
|
on `unittest <http://pytest.org/latest/unittest.html>`_ (or trial),
|
||||||
`nose <http://pytest.org/latest/nose.html>`_
|
`nose <http://pytest.org/latest/nose.html>`_
|
||||||
- single-source compatibility to Python2.4 all the way up to Python3.3,
|
- single-source compatibility to Python2.4 all the way up to Python3.3,
|
||||||
|
|
|
@ -15,7 +15,7 @@ import py
|
||||||
from _pytest.assertion import util
|
from _pytest.assertion import util
|
||||||
|
|
||||||
|
|
||||||
# py.test caches rewritten pycs in __pycache__.
|
# pytest caches rewritten pycs in __pycache__.
|
||||||
if hasattr(imp, "get_tag"):
|
if hasattr(imp, "get_tag"):
|
||||||
PYTEST_TAG = imp.get_tag() + "-PYTEST"
|
PYTEST_TAG = imp.get_tag() + "-PYTEST"
|
||||||
else:
|
else:
|
||||||
|
@ -102,7 +102,7 @@ class AssertionRewritingHook(object):
|
||||||
# the most magical part of the process: load the source, rewrite the
|
# the most magical part of the process: load the source, rewrite the
|
||||||
# asserts, and load the rewritten source. We also cache the rewritten
|
# asserts, and load the rewritten source. We also cache the rewritten
|
||||||
# module code in a special pyc. We must be aware of the possibility of
|
# module code in a special pyc. We must be aware of the possibility of
|
||||||
# concurrent py.test processes rewriting and loading pycs. To avoid
|
# concurrent pytest processes rewriting and loading pycs. To avoid
|
||||||
# tricky race conditions, we maintain the following invariant: The
|
# tricky race conditions, we maintain the following invariant: The
|
||||||
# cached pyc is always a complete, valid pyc. Operations on it must be
|
# cached pyc is always a complete, valid pyc. Operations on it must be
|
||||||
# atomic. POSIX's atomic rename comes in handy.
|
# atomic. POSIX's atomic rename comes in handy.
|
||||||
|
@ -290,7 +290,7 @@ def _make_rewritten_pyc(state, fn, pyc, co):
|
||||||
os.rename(proc_pyc, pyc)
|
os.rename(proc_pyc, pyc)
|
||||||
|
|
||||||
def _read_pyc(source, pyc):
|
def _read_pyc(source, pyc):
|
||||||
"""Possibly read a py.test pyc containing rewritten code.
|
"""Possibly read a pytest pyc containing rewritten code.
|
||||||
|
|
||||||
Return rewritten code if successful or None if not.
|
Return rewritten code if successful or None if not.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
""" command line options, ini-file and conftest.py processing. """
|
""" command line options, ini-file and conftest.py processing. """
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
import pytest
|
||||||
import sys, os
|
import sys, os
|
||||||
from _pytest import hookspec # the extension point definitions
|
from _pytest import hookspec # the extension point definitions
|
||||||
from _pytest.core import PluginManager
|
from _pytest.core import PluginManager
|
||||||
|
@ -22,7 +23,7 @@ class cmdline: # compatibility namespace
|
||||||
main = staticmethod(main)
|
main = staticmethod(main)
|
||||||
|
|
||||||
class UsageError(Exception):
|
class UsageError(Exception):
|
||||||
""" error in py.test usage or invocation"""
|
""" error in pytest usage or invocation"""
|
||||||
|
|
||||||
_preinit = []
|
_preinit = []
|
||||||
|
|
||||||
|
@ -225,7 +226,7 @@ class Argument:
|
||||||
help = attrs['help']
|
help = attrs['help']
|
||||||
if '%default' in help:
|
if '%default' in help:
|
||||||
py.std.warnings.warn(
|
py.std.warnings.warn(
|
||||||
'py.test now uses argparse. "%default" should be'
|
'pytest now uses argparse. "%default" should be'
|
||||||
' changed to "%(default)s" ',
|
' changed to "%(default)s" ',
|
||||||
FutureWarning,
|
FutureWarning,
|
||||||
stacklevel=3)
|
stacklevel=3)
|
||||||
|
@ -448,7 +449,7 @@ class DropShorterLongHelpFormatter(py.std.argparse.HelpFormatter):
|
||||||
|
|
||||||
class Conftest(object):
|
class Conftest(object):
|
||||||
""" the single place for accessing values and interacting
|
""" the single place for accessing values and interacting
|
||||||
towards conftest modules from py.test objects.
|
towards conftest modules from pytest objects.
|
||||||
"""
|
"""
|
||||||
def __init__(self, onimport=None, confcutdir=None):
|
def __init__(self, onimport=None, confcutdir=None):
|
||||||
self._path2confmods = {}
|
self._path2confmods = {}
|
||||||
|
@ -808,7 +809,7 @@ class Config(object):
|
||||||
|
|
||||||
def getvalueorskip(self, name, path=None):
|
def getvalueorskip(self, name, path=None):
|
||||||
""" (deprecated) return getvalue(name) or call
|
""" (deprecated) return getvalue(name) or call
|
||||||
py.test.skip if no value exists. """
|
pytest.skip if no value exists. """
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
try:
|
try:
|
||||||
val = self.getvalue(name, path)
|
val = self.getvalue(name, path)
|
||||||
|
@ -816,7 +817,7 @@ class Config(object):
|
||||||
raise KeyError(name)
|
raise KeyError(name)
|
||||||
return val
|
return val
|
||||||
except KeyError:
|
except KeyError:
|
||||||
py.test.skip("no %r value found" %(name,))
|
pytest.skip("no %r value found" %(name,))
|
||||||
|
|
||||||
def exists(path, ignore=EnvironmentError):
|
def exists(path, ignore=EnvironmentError):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -4,6 +4,7 @@ pytest PluginManager, basic initialization and tracing.
|
||||||
import sys
|
import sys
|
||||||
import inspect
|
import inspect
|
||||||
import py
|
import py
|
||||||
|
import pytest
|
||||||
|
|
||||||
assert py.__version__.split(".")[:2] >= ['1', '4'], ("installation problem: "
|
assert py.__version__.split(".")[:2] >= ['1', '4'], ("installation problem: "
|
||||||
"%s is too old, remove or upgrade 'py'" % (py.__version__))
|
"%s is too old, remove or upgrade 'py'" % (py.__version__))
|
||||||
|
@ -136,7 +137,7 @@ class PluginManager(object):
|
||||||
|
|
||||||
def skipifmissing(self, name):
|
def skipifmissing(self, name):
|
||||||
if not self.hasplugin(name):
|
if not self.hasplugin(name):
|
||||||
py.test.skip("plugin %r is missing" % name)
|
pytest.skip("plugin %r is missing" % name)
|
||||||
|
|
||||||
def hasplugin(self, name):
|
def hasplugin(self, name):
|
||||||
return bool(self.getplugin(name))
|
return bool(self.getplugin(name))
|
||||||
|
@ -220,9 +221,9 @@ class PluginManager(object):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
e = py.std.sys.exc_info()[1]
|
e = py.std.sys.exc_info()[1]
|
||||||
if not hasattr(py.test, 'skip'):
|
if not hasattr(pytest, 'skip'):
|
||||||
raise
|
raise
|
||||||
elif not isinstance(e, py.test.skip.Exception):
|
elif not isinstance(e, pytest.skip.Exception):
|
||||||
raise
|
raise
|
||||||
self._hints.append("skipped plugin %r: %s" %((modname, e.msg)))
|
self._hints.append("skipped plugin %r: %s" %((modname, e.msg)))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
""" generate a single-file self-contained version of py.test """
|
""" generate a single-file self-contained version of pytest """
|
||||||
import py
|
import py
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ def pytest_addoption(parser):
|
||||||
group = parser.getgroup("debugconfig")
|
group = parser.getgroup("debugconfig")
|
||||||
group.addoption("--genscript", action="store", default=None,
|
group.addoption("--genscript", action="store", default=None,
|
||||||
dest="genscript", metavar="path",
|
dest="genscript", metavar="path",
|
||||||
help="create standalone py.test script at given target path.")
|
help="create standalone pytest script at given target path.")
|
||||||
|
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
genscript = config.getvalue("genscript")
|
genscript = config.getvalue("genscript")
|
||||||
|
@ -70,7 +70,7 @@ def pytest_cmdline_main(config):
|
||||||
"or below due to 'argparse' dependency. Use python2.6 "
|
"or below due to 'argparse' dependency. Use python2.6 "
|
||||||
"to generate a python2.5/6 compatible script", red=True)
|
"to generate a python2.5/6 compatible script", red=True)
|
||||||
script = generate_script(
|
script = generate_script(
|
||||||
'import py; raise SystemExit(py.test.cmdline.main())',
|
'import pytest; raise SystemExit(pytest.cmdline.main())',
|
||||||
deps,
|
deps,
|
||||||
)
|
)
|
||||||
genscript = py.path.local(genscript)
|
genscript = py.path.local(genscript)
|
||||||
|
|
|
@ -46,7 +46,7 @@ def pytest_unconfigure(config):
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
if config.option.version:
|
if config.option.version:
|
||||||
p = py.path.local(pytest.__file__)
|
p = py.path.local(pytest.__file__)
|
||||||
sys.stderr.write("This is py.test version %s, imported from %s\n" %
|
sys.stderr.write("This is pytest version %s, imported from %s\n" %
|
||||||
(pytest.__version__, p))
|
(pytest.__version__, p))
|
||||||
plugininfo = getpluginversioninfo(config)
|
plugininfo = getpluginversioninfo(config)
|
||||||
if plugininfo:
|
if plugininfo:
|
||||||
|
|
|
@ -11,8 +11,8 @@ def pytest_addhooks(pluginmanager):
|
||||||
|
|
||||||
def pytest_namespace():
|
def pytest_namespace():
|
||||||
"""return dict of name->object to be made globally available in
|
"""return dict of name->object to be made globally available in
|
||||||
the py.test/pytest namespace. This hook is called before command
|
the pytest namespace. This hook is called before command line options
|
||||||
line options are parsed.
|
are parsed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def pytest_cmdline_parse(pluginmanager, args):
|
def pytest_cmdline_parse(pluginmanager, args):
|
||||||
|
|
|
@ -63,7 +63,7 @@ def pytest_namespace():
|
||||||
return dict(collect=collect)
|
return dict(collect=collect)
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
py.test.config = config # compatibiltiy
|
pytest.config = config # compatibiltiy
|
||||||
if config.option.exitfirst:
|
if config.option.exitfirst:
|
||||||
config.option.maxfail = 1
|
config.option.maxfail = 1
|
||||||
|
|
||||||
|
|
|
@ -157,10 +157,10 @@ def pytest_configure(config):
|
||||||
|
|
||||||
class MarkGenerator:
|
class MarkGenerator:
|
||||||
""" Factory for :class:`MarkDecorator` objects - exposed as
|
""" Factory for :class:`MarkDecorator` objects - exposed as
|
||||||
a ``py.test.mark`` singleton instance. Example::
|
a ``pytest.mark`` singleton instance. Example::
|
||||||
|
|
||||||
import py
|
import py
|
||||||
@py.test.mark.slowtest
|
@pytest.mark.slowtest
|
||||||
def test_function():
|
def test_function():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -198,8 +198,8 @@ class MarkDecorator:
|
||||||
:ref:`retrieved by hooks as item keywords <excontrolskip>`.
|
:ref:`retrieved by hooks as item keywords <excontrolskip>`.
|
||||||
MarkDecorator instances are often created like this::
|
MarkDecorator instances are often created like this::
|
||||||
|
|
||||||
mark1 = py.test.mark.NAME # simple MarkDecorator
|
mark1 = pytest.mark.NAME # simple MarkDecorator
|
||||||
mark2 = py.test.mark.NAME(name1=value) # parametrized MarkDecorator
|
mark2 = pytest.mark.NAME(name1=value) # parametrized MarkDecorator
|
||||||
|
|
||||||
and can then be applied as decorators to test functions::
|
and can then be applied as decorators to test functions::
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ def pytest_runtest_makereport(__multicall__, item, call):
|
||||||
SkipTest = getattr(sys.modules.get('nose', None), 'SkipTest', None)
|
SkipTest = getattr(sys.modules.get('nose', None), 'SkipTest', None)
|
||||||
if SkipTest:
|
if SkipTest:
|
||||||
if call.excinfo and call.excinfo.errisinstance(SkipTest):
|
if call.excinfo and call.excinfo.errisinstance(SkipTest):
|
||||||
# let's substitute the excinfo with a py.test.skip one
|
# let's substitute the excinfo with a pytest.skip one
|
||||||
call2 = call.__class__(lambda:
|
call2 = call.__class__(lambda:
|
||||||
pytest.skip(str(call.excinfo.value)), call.when)
|
pytest.skip(str(call.excinfo.value)), call.when)
|
||||||
call.excinfo = call2.excinfo
|
call.excinfo = call2.excinfo
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
""" (disabled by default) support for testing py.test and py.test plugins. """
|
""" (disabled by default) support for testing pytest and pytest plugins. """
|
||||||
|
|
||||||
import py, pytest
|
import py, pytest
|
||||||
import sys, os
|
import sys, os
|
||||||
|
@ -137,7 +137,7 @@ class HookRecorder:
|
||||||
break
|
break
|
||||||
print_("NONAMEMATCH", name, "with", call)
|
print_("NONAMEMATCH", name, "with", call)
|
||||||
else:
|
else:
|
||||||
py.test.fail("could not find %r check %r" % (name, check))
|
pytest.fail("could not find %r check %r" % (name, check))
|
||||||
|
|
||||||
def popcall(self, name):
|
def popcall(self, name):
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
|
@ -147,7 +147,7 @@ class HookRecorder:
|
||||||
return call
|
return call
|
||||||
lines = ["could not find call %r, in:" % (name,)]
|
lines = ["could not find call %r, in:" % (name,)]
|
||||||
lines.extend([" %s" % str(x) for x in self.calls])
|
lines.extend([" %s" % str(x) for x in self.calls])
|
||||||
py.test.fail("\n".join(lines))
|
pytest.fail("\n".join(lines))
|
||||||
|
|
||||||
def getcall(self, name):
|
def getcall(self, name):
|
||||||
l = self.getcalls(name)
|
l = self.getcalls(name)
|
||||||
|
@ -472,7 +472,7 @@ class TmpTestdir:
|
||||||
# becaue on windows the script is e.g. a py.test.exe
|
# becaue on windows the script is e.g. a py.test.exe
|
||||||
return (py.std.sys.executable, _pytest_fullpath,) # noqa
|
return (py.std.sys.executable, _pytest_fullpath,) # noqa
|
||||||
else:
|
else:
|
||||||
py.test.skip("cannot run %r with --no-tools-on-path" % scriptname)
|
pytest.skip("cannot run %r with --no-tools-on-path" % scriptname)
|
||||||
|
|
||||||
def runpython(self, script, prepend=True):
|
def runpython(self, script, prepend=True):
|
||||||
if prepend:
|
if prepend:
|
||||||
|
@ -509,14 +509,14 @@ class TmpTestdir:
|
||||||
|
|
||||||
def spawn_pytest(self, string, expect_timeout=10.0):
|
def spawn_pytest(self, string, expect_timeout=10.0):
|
||||||
if self.request.config.getvalue("notoolsonpath"):
|
if self.request.config.getvalue("notoolsonpath"):
|
||||||
py.test.skip("--no-tools-on-path prevents running pexpect-spawn tests")
|
pytest.skip("--no-tools-on-path prevents running pexpect-spawn tests")
|
||||||
basetemp = self.tmpdir.mkdir("pexpect")
|
basetemp = self.tmpdir.mkdir("pexpect")
|
||||||
invoke = " ".join(map(str, self._getpybinargs("py.test")))
|
invoke = " ".join(map(str, self._getpybinargs("py.test")))
|
||||||
cmd = "%s --basetemp=%s %s" % (invoke, basetemp, string)
|
cmd = "%s --basetemp=%s %s" % (invoke, basetemp, string)
|
||||||
return self.spawn(cmd, expect_timeout=expect_timeout)
|
return self.spawn(cmd, expect_timeout=expect_timeout)
|
||||||
|
|
||||||
def spawn(self, cmd, expect_timeout=10.0):
|
def spawn(self, cmd, expect_timeout=10.0):
|
||||||
pexpect = py.test.importorskip("pexpect", "3.0")
|
pexpect = pytest.importorskip("pexpect", "3.0")
|
||||||
if hasattr(sys, 'pypy_version_info') and '64' in py.std.platform.machine():
|
if hasattr(sys, 'pypy_version_info') and '64' in py.std.platform.machine():
|
||||||
pytest.skip("pypy-64 bit not supported")
|
pytest.skip("pypy-64 bit not supported")
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
|
@ -688,4 +688,4 @@ class LineMatcher:
|
||||||
show(" and:", repr(nextline))
|
show(" and:", repr(nextline))
|
||||||
extralines.append(nextline)
|
extralines.append(nextline)
|
||||||
else:
|
else:
|
||||||
py.test.fail("remains unmatched: %r, see stderr" % (line,))
|
pytest.fail("remains unmatched: %r, see stderr" % (line,))
|
||||||
|
|
|
@ -485,7 +485,7 @@ class Module(pytest.File, PyCollector):
|
||||||
fin = getattr(self.obj, 'teardown_module', None)
|
fin = getattr(self.obj, 'teardown_module', None)
|
||||||
if fin is not None:
|
if fin is not None:
|
||||||
#XXX: nose compat hack, move to nose plugin
|
#XXX: nose compat hack, move to nose plugin
|
||||||
# if it takes a positional arg, its probably a py.test style one
|
# if it takes a positional arg, its probably a pytest style one
|
||||||
# so we pass the current module object
|
# so we pass the current module object
|
||||||
if inspect.getargspec(fin)[0]:
|
if inspect.getargspec(fin)[0]:
|
||||||
finalizer = lambda: fin(self.obj)
|
finalizer = lambda: fin(self.obj)
|
||||||
|
@ -1011,7 +1011,7 @@ class RaisesContext(object):
|
||||||
return issubclass(self.excinfo.type, self.ExpectedException)
|
return issubclass(self.excinfo.type, self.ExpectedException)
|
||||||
|
|
||||||
#
|
#
|
||||||
# the basic py.test Function item
|
# the basic pytest Function item
|
||||||
#
|
#
|
||||||
|
|
||||||
class Function(FunctionMixin, pytest.Item, FuncargnamesCompatAttr):
|
class Function(FunctionMixin, pytest.Item, FuncargnamesCompatAttr):
|
||||||
|
@ -1225,7 +1225,7 @@ class FixtureRequest(FuncargnamesCompatAttr):
|
||||||
on all function invocations.
|
on all function invocations.
|
||||||
|
|
||||||
:arg marker: a :py:class:`_pytest.mark.MarkDecorator` object
|
:arg marker: a :py:class:`_pytest.mark.MarkDecorator` object
|
||||||
created by a call to ``py.test.mark.NAME(...)``.
|
created by a call to ``pytest.mark.NAME(...)``.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.node.keywords[marker.markname] = marker
|
self.node.keywords[marker.markname] = marker
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
""" basic collect and runtest protocol implementations """
|
""" basic collect and runtest protocol implementations """
|
||||||
|
|
||||||
import py, sys
|
import py
|
||||||
|
import pytest
|
||||||
|
import sys
|
||||||
from time import time
|
from time import time
|
||||||
from py._code.code import TerminalRepr
|
from py._code.code import TerminalRepr
|
||||||
|
|
||||||
|
@ -196,7 +198,7 @@ def pytest_runtest_makereport(item, call):
|
||||||
if not isinstance(excinfo, py.code.ExceptionInfo):
|
if not isinstance(excinfo, py.code.ExceptionInfo):
|
||||||
outcome = "failed"
|
outcome = "failed"
|
||||||
longrepr = excinfo
|
longrepr = excinfo
|
||||||
elif excinfo.errisinstance(py.test.skip.Exception):
|
elif excinfo.errisinstance(pytest.skip.Exception):
|
||||||
outcome = "skipped"
|
outcome = "skipped"
|
||||||
r = excinfo._getreprcrash()
|
r = excinfo._getreprcrash()
|
||||||
longrepr = (str(r.path), r.lineno, r.message)
|
longrepr = (str(r.path), r.lineno, r.message)
|
||||||
|
@ -418,7 +420,7 @@ class Skipped(OutcomeException):
|
||||||
__module__ = 'builtins'
|
__module__ = 'builtins'
|
||||||
|
|
||||||
class Failed(OutcomeException):
|
class Failed(OutcomeException):
|
||||||
""" raised from an explicit call to py.test.fail() """
|
""" raised from an explicit call to pytest.fail() """
|
||||||
__module__ = 'builtins'
|
__module__ = 'builtins'
|
||||||
|
|
||||||
class Exit(KeyboardInterrupt):
|
class Exit(KeyboardInterrupt):
|
||||||
|
@ -438,7 +440,7 @@ exit.Exception = Exit
|
||||||
|
|
||||||
def skip(msg=""):
|
def skip(msg=""):
|
||||||
""" skip an executing test with the given message. Note: it's usually
|
""" skip an executing test with the given message. Note: it's usually
|
||||||
better to use the py.test.mark.skipif marker to declare a test to be
|
better to use the pytest.mark.skipif marker to declare a test to be
|
||||||
skipped under certain conditions like mismatching platforms or
|
skipped under certain conditions like mismatching platforms or
|
||||||
dependencies. See the pytest_skipping plugin for details.
|
dependencies. See the pytest_skipping plugin for details.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -37,7 +37,7 @@ def pytest_namespace():
|
||||||
return dict(xfail=xfail)
|
return dict(xfail=xfail)
|
||||||
|
|
||||||
class XFailed(pytest.fail.Exception):
|
class XFailed(pytest.fail.Exception):
|
||||||
""" raised from an explicit call to py.test.xfail() """
|
""" raised from an explicit call to pytest.xfail() """
|
||||||
|
|
||||||
def xfail(reason=""):
|
def xfail(reason=""):
|
||||||
""" xfail an executing test or setup functions with the given reason."""
|
""" xfail an executing test or setup functions with the given reason."""
|
||||||
|
@ -129,7 +129,7 @@ def pytest_runtest_setup(item):
|
||||||
return
|
return
|
||||||
evalskip = MarkEvaluator(item, 'skipif')
|
evalskip = MarkEvaluator(item, 'skipif')
|
||||||
if evalskip.istrue():
|
if evalskip.istrue():
|
||||||
py.test.skip(evalskip.getexplanation())
|
pytest.skip(evalskip.getexplanation())
|
||||||
item._evalxfail = MarkEvaluator(item, 'xfail')
|
item._evalxfail = MarkEvaluator(item, 'xfail')
|
||||||
check_xfail_no_run(item)
|
check_xfail_no_run(item)
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ def check_xfail_no_run(item):
|
||||||
evalxfail = item._evalxfail
|
evalxfail = item._evalxfail
|
||||||
if evalxfail.istrue():
|
if evalxfail.istrue():
|
||||||
if not evalxfail.get('run', True):
|
if not evalxfail.get('run', True):
|
||||||
py.test.xfail("[NOTRUN] " + evalxfail.getexplanation())
|
pytest.xfail("[NOTRUN] " + evalxfail.getexplanation())
|
||||||
|
|
||||||
def pytest_runtest_makereport(__multicall__, item, call):
|
def pytest_runtest_makereport(__multicall__, item, call):
|
||||||
if not isinstance(item, pytest.Function):
|
if not isinstance(item, pytest.Function):
|
||||||
|
@ -150,16 +150,16 @@ def pytest_runtest_makereport(__multicall__, item, call):
|
||||||
if hasattr(item, '_unexpectedsuccess'):
|
if hasattr(item, '_unexpectedsuccess'):
|
||||||
rep = __multicall__.execute()
|
rep = __multicall__.execute()
|
||||||
if rep.when == "call":
|
if rep.when == "call":
|
||||||
# we need to translate into how py.test encodes xpass
|
# we need to translate into how pytest encodes xpass
|
||||||
rep.wasxfail = "reason: " + repr(item._unexpectedsuccess)
|
rep.wasxfail = "reason: " + repr(item._unexpectedsuccess)
|
||||||
rep.outcome = "failed"
|
rep.outcome = "failed"
|
||||||
return rep
|
return rep
|
||||||
if not (call.excinfo and
|
if not (call.excinfo and
|
||||||
call.excinfo.errisinstance(py.test.xfail.Exception)):
|
call.excinfo.errisinstance(pytest.xfail.Exception)):
|
||||||
evalxfail = getattr(item, '_evalxfail', None)
|
evalxfail = getattr(item, '_evalxfail', None)
|
||||||
if not evalxfail:
|
if not evalxfail:
|
||||||
return
|
return
|
||||||
if call.excinfo and call.excinfo.errisinstance(py.test.xfail.Exception):
|
if call.excinfo and call.excinfo.errisinstance(pytest.xfail.Exception):
|
||||||
if not item.config.getvalue("runxfail"):
|
if not item.config.getvalue("runxfail"):
|
||||||
rep = __multicall__.execute()
|
rep = __multicall__.execute()
|
||||||
rep.wasxfail = "reason: " + call.excinfo.value.msg
|
rep.wasxfail = "reason: " + call.excinfo.value.msg
|
||||||
|
|
|
@ -259,7 +259,7 @@ class TerminalReporter:
|
||||||
if hasattr(sys, 'pypy_version_info'):
|
if hasattr(sys, 'pypy_version_info'):
|
||||||
verinfo = ".".join(map(str, sys.pypy_version_info[:3]))
|
verinfo = ".".join(map(str, sys.pypy_version_info[:3]))
|
||||||
msg += "[pypy-%s-%s]" % (verinfo, sys.pypy_version_info[3])
|
msg += "[pypy-%s-%s]" % (verinfo, sys.pypy_version_info[3])
|
||||||
msg += " -- pytest-%s" % (py.test.__version__)
|
msg += " -- pytest-%s" % (pytest.__version__)
|
||||||
if self.verbosity > 0 or self.config.option.debug or \
|
if self.verbosity > 0 or self.config.option.debug or \
|
||||||
getattr(self.config.option, 'pastebin', None):
|
getattr(self.config.option, 'pastebin', None):
|
||||||
msg += " -- " + str(sys.executable)
|
msg += " -- " + str(sys.executable)
|
||||||
|
|
|
@ -2,10 +2,10 @@ import sys
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import cProfile
|
import cProfile
|
||||||
import py
|
import pytest
|
||||||
import pstats
|
import pstats
|
||||||
script = sys.argv[1] if len(sys.argv) > 1 else "empty.py"
|
script = sys.argv[1] if len(sys.argv) > 1 else "empty.py"
|
||||||
stats = cProfile.run('py.test.cmdline.main([%r])' % script, 'prof')
|
stats = cProfile.run('pytest.cmdline.main([%r])' % script, 'prof')
|
||||||
p = pstats.Stats("prof")
|
p = pstats.Stats("prof")
|
||||||
p.strip_dirs()
|
p.strip_dirs()
|
||||||
p.sort_stats('cumulative')
|
p.sort_stats('cumulative')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
.. _apiref:
|
.. _apiref:
|
||||||
|
|
||||||
py.test reference documentation
|
pytest reference documentation
|
||||||
================================================
|
================================================
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
|
|
@ -10,7 +10,7 @@ The writing and reporting of assertions in tests
|
||||||
Asserting with the ``assert`` statement
|
Asserting with the ``assert`` statement
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
``py.test`` allows you to use the standard python ``assert`` for verifying
|
``pytest`` allows you to use the standard python ``assert`` for verifying
|
||||||
expectations and values in Python tests. For example, you can write the
|
expectations and values in Python tests. For example, you can write the
|
||||||
following::
|
following::
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ you will see the return value of the function call::
|
||||||
test_assert1.py:5: AssertionError
|
test_assert1.py:5: AssertionError
|
||||||
========================= 1 failed in 0.01 seconds =========================
|
========================= 1 failed in 0.01 seconds =========================
|
||||||
|
|
||||||
py.test has support for showing the values of the most common subexpressions
|
``pytest`` has support for showing the values of the most common subexpressions
|
||||||
including calls, attributes, comparisons, and binary and unary
|
including calls, attributes, comparisons, and binary and unary
|
||||||
operators. (See :ref:`tbreportdemo`). This allows you to use the
|
operators. (See :ref:`tbreportdemo`). This allows you to use the
|
||||||
idiomatic python constructs without boilerplate code while not losing
|
idiomatic python constructs without boilerplate code while not losing
|
||||||
|
@ -102,7 +102,7 @@ Making use of context-sensitive comparisons
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
py.test has rich support for providing context-sensitive information
|
``pytest`` has rich support for providing context-sensitive information
|
||||||
when it encounters comparisons. For example::
|
when it encounters comparisons. For example::
|
||||||
|
|
||||||
# content of test_assert2.py
|
# content of test_assert2.py
|
||||||
|
@ -205,33 +205,33 @@ Advanced assertion introspection
|
||||||
Reporting details about a failing assertion is achieved either by rewriting
|
Reporting details about a failing assertion is achieved either by rewriting
|
||||||
assert statements before they are run or re-evaluating the assert expression and
|
assert statements before they are run or re-evaluating the assert expression and
|
||||||
recording the intermediate values. Which technique is used depends on the
|
recording the intermediate values. Which technique is used depends on the
|
||||||
location of the assert, py.test's configuration, and Python version being used
|
location of the assert, ``pytest`` configuration, and Python version being used
|
||||||
to run py.test. Note that for assert statements with a manually provided
|
to run ``pytest``. Note that for assert statements with a manually provided
|
||||||
message, i.e. ``assert expr, message``, no assertion introspection takes place
|
message, i.e. ``assert expr, message``, no assertion introspection takes place
|
||||||
and the manually provided message will be rendered in tracebacks.
|
and the manually provided message will be rendered in tracebacks.
|
||||||
|
|
||||||
By default, if the Python version is greater than or equal to 2.6, py.test
|
By default, if the Python version is greater than or equal to 2.6, ``pytest``
|
||||||
rewrites assert statements in test modules. Rewritten assert statements put
|
rewrites assert statements in test modules. Rewritten assert statements put
|
||||||
introspection information into the assertion failure message. py.test only
|
introspection information into the assertion failure message. ``pytest`` only
|
||||||
rewrites test modules directly discovered by its test collection process, so
|
rewrites test modules directly discovered by its test collection process, so
|
||||||
asserts in supporting modules which are not themselves test modules will not be
|
asserts in supporting modules which are not themselves test modules will not be
|
||||||
rewritten.
|
rewritten.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
py.test rewrites test modules on import. It does this by using an import hook
|
``pytest`` rewrites test modules on import. It does this by using an import
|
||||||
to write a new pyc files. Most of the time this works transparently. However,
|
hook to write a new pyc files. Most of the time this works transparently.
|
||||||
if you are messing with import yourself, the import hook may interfere. If
|
However, if you are messing with import yourself, the import hook may
|
||||||
this is the case, simply use ``--assert=reinterp`` or
|
interfere. If this is the case, simply use ``--assert=reinterp`` or
|
||||||
``--assert=plain``. Additionally, rewriting will fail silently if it cannot
|
``--assert=plain``. Additionally, rewriting will fail silently if it cannot
|
||||||
write new pycs, i.e. in a read-only filesystem or a zipfile.
|
write new pycs, i.e. in a read-only filesystem or a zipfile.
|
||||||
|
|
||||||
If an assert statement has not been rewritten or the Python version is less than
|
If an assert statement has not been rewritten or the Python version is less than
|
||||||
2.6, py.test falls back on assert reinterpretation. In assert reinterpretation,
|
2.6, ``pytest`` falls back on assert reinterpretation. In assert
|
||||||
py.test walks the frame of the function containing the assert statement to
|
reinterpretation, ``pytest`` walks the frame of the function containing the
|
||||||
discover sub-expression results of the failing assert statement. You can force
|
assert statement to discover sub-expression results of the failing assert
|
||||||
py.test to always use assertion reinterpretation by passing the
|
statement. You can force ``pytest`` to always use assertion reinterpretation by
|
||||||
``--assert=reinterp`` option.
|
passing the ``--assert=reinterp`` option.
|
||||||
|
|
||||||
Assert reinterpretation has a caveat not present with assert rewriting: If
|
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
|
evaluating the assert expression has side effects you may get a warning that the
|
||||||
|
@ -250,7 +250,7 @@ easy to rewrite the assertion and avoid any trouble::
|
||||||
|
|
||||||
All assert introspection can be turned off by passing ``--assert=plain``.
|
All assert introspection can be turned off by passing ``--assert=plain``.
|
||||||
|
|
||||||
For further information, Benjamin Peterson wrote up `Behind the scenes of py.test's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_.
|
For further information, Benjamin Peterson wrote up `Behind the scenes of pytest's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_.
|
||||||
|
|
||||||
.. versionadded:: 2.1
|
.. versionadded:: 2.1
|
||||||
Add assert rewriting as an alternate introspection technique.
|
Add assert rewriting as an alternate introspection technique.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
Setting up bash completion
|
Setting up bash completion
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
When using bash as your shell, ``py.test`` can use argcomplete
|
When using bash as your shell, ``pytest`` can use argcomplete
|
||||||
(https://argcomplete.readthedocs.org/) for auto-completion.
|
(https://argcomplete.readthedocs.org/) for auto-completion.
|
||||||
For this ``argcomplete`` needs to be installed **and** enabled.
|
For this ``argcomplete`` needs to be installed **and** enabled.
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ For global activation of all argcomplete enabled python applications run::
|
||||||
|
|
||||||
sudo activate-global-python-argcomplete
|
sudo activate-global-python-argcomplete
|
||||||
|
|
||||||
For permanent (but not global) ``py.test`` activation, use::
|
For permanent (but not global) ``pytest`` activation, use::
|
||||||
|
|
||||||
register-python-argcomplete py.test >> ~/.bashrc
|
register-python-argcomplete py.test >> ~/.bashrc
|
||||||
|
|
||||||
For one-time activation of argcomplete for ``py.test`` only, use::
|
For one-time activation of argcomplete for ``pytest`` only, use::
|
||||||
|
|
||||||
eval "$(register-python-argcomplete py.test)"
|
eval "$(register-python-argcomplete py.test)"
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ a test.
|
||||||
Setting capturing methods or disabling capturing
|
Setting capturing methods or disabling capturing
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
There are two ways in which ``py.test`` can perform capturing:
|
There are two ways in which ``pytest`` can perform capturing:
|
||||||
|
|
||||||
* file descriptor (FD) level capturing (default): All writes going to the
|
* file descriptor (FD) level capturing (default): All writes going to the
|
||||||
operating system file descriptors 1 and 2 will be captured.
|
operating system file descriptors 1 and 2 will be captured.
|
||||||
|
@ -105,7 +105,7 @@ and capturing will be continued. After the test
|
||||||
function finishes the original streams will
|
function finishes the original streams will
|
||||||
be restored. Using ``capsys`` this way frees your
|
be restored. Using ``capsys`` this way frees your
|
||||||
test from having to care about setting/resetting
|
test from having to care about setting/resetting
|
||||||
output streams and also interacts well with py.test's
|
output streams and also interacts well with pytest's
|
||||||
own per-test capturing.
|
own per-test capturing.
|
||||||
|
|
||||||
If you want to capture on ``fd`` level you can use
|
If you want to capture on ``fd`` level you can use
|
||||||
|
|
|
@ -17,7 +17,7 @@ which were registered by installed plugins.
|
||||||
How test configuration is read from configuration INI-files
|
How test configuration is read from configuration INI-files
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
|
||||||
py.test searches for the first matching ini-style configuration file
|
``pytest`` searches for the first matching ini-style configuration file
|
||||||
in the directories of command line argument and the directories above.
|
in the directories of command line argument and the directories above.
|
||||||
It looks for file basenames in this order::
|
It looks for file basenames in this order::
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ will look in the following dirs for a config file::
|
||||||
path/to/setup.cfg
|
path/to/setup.cfg
|
||||||
... # up until root of filesystem
|
... # up until root of filesystem
|
||||||
|
|
||||||
If argument is provided to a py.test run, the current working directory
|
If argument is provided to a ``pytest`` run, the current working directory
|
||||||
is used to start the search.
|
is used to start the search.
|
||||||
|
|
||||||
.. _`how to change command line options defaults`:
|
.. _`how to change command line options defaults`:
|
||||||
|
@ -51,7 +51,7 @@ How to change command line options defaults
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|
||||||
It can be tedious to type the same series of command line options
|
It can be tedious to type the same series of command line options
|
||||||
every time you use py.test . For example, if you always want to see
|
every time you use ``pytest``. For example, if you always want to see
|
||||||
detailed info on skipped and xfailed tests, as well as have terser "dot"
|
detailed info on skipped and xfailed tests, as well as have terser "dot"
|
||||||
progress output, you can write it into a configuration file::
|
progress output, you can write it into a configuration file::
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ progress output, you can write it into a configuration file::
|
||||||
[pytest]
|
[pytest]
|
||||||
addopts = -rsxX -q
|
addopts = -rsxX -q
|
||||||
|
|
||||||
From now on, running ``py.test`` will add the specified options.
|
From now on, running ``pytest`` will add the specified options.
|
||||||
|
|
||||||
Builtin configuration file options
|
Builtin configuration file options
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
@ -105,7 +105,7 @@ Builtin configuration file options
|
||||||
[pytest]
|
[pytest]
|
||||||
norecursedirs = .svn _build tmp*
|
norecursedirs = .svn _build tmp*
|
||||||
|
|
||||||
This would tell py.test to not look into typical subversion or
|
This would tell ``pytest`` to not look into typical subversion or
|
||||||
sphinx-build directories or into any ``tmp`` prefixed directory.
|
sphinx-build directories or into any ``tmp`` prefixed directory.
|
||||||
|
|
||||||
.. confval:: python_files
|
.. confval:: python_files
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=================================================
|
=================================================
|
||||||
Feedback and contribute to py.test
|
Feedback and contribute to pytest
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from py.test import raises
|
from pytest import raises
|
||||||
import py
|
import py
|
||||||
|
|
||||||
def otherfunc(a,b):
|
def otherfunc(a,b):
|
||||||
|
|
|
@ -150,8 +150,8 @@ For an example on how to add and work with markers from a plugin, see
|
||||||
* asking for existing markers via ``py.test --markers`` gives good output
|
* asking for existing markers via ``py.test --markers`` gives good output
|
||||||
|
|
||||||
* typos in function markers are treated as an error if you use
|
* typos in function markers are treated as an error if you use
|
||||||
the ``--strict`` option. Later versions of py.test are probably
|
the ``--strict`` option. Future versions of ``pytest`` are probably
|
||||||
going to treat non-registered markers as an error.
|
going to start treating non-registered markers as errors at some point.
|
||||||
|
|
||||||
.. _`scoped-marking`:
|
.. _`scoped-marking`:
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
module containing a parametrized tests testing cross-python
|
module containing a parametrized tests testing cross-python
|
||||||
serialization via the pickle module.
|
serialization via the pickle module.
|
||||||
"""
|
"""
|
||||||
import py, pytest
|
import py
|
||||||
|
import pytest
|
||||||
|
|
||||||
pythonlist = ['python2.4', 'python2.5', 'python2.6', 'python2.7', 'python2.8']
|
pythonlist = ['python2.4', 'python2.5', 'python2.6', 'python2.7', 'python2.8']
|
||||||
@pytest.fixture(params=pythonlist)
|
@pytest.fixture(params=pythonlist)
|
||||||
|
@ -18,7 +19,7 @@ class Python:
|
||||||
def __init__(self, version, picklefile):
|
def __init__(self, version, picklefile):
|
||||||
self.pythonpath = py.path.local.sysfind(version)
|
self.pythonpath = py.path.local.sysfind(version)
|
||||||
if not self.pythonpath:
|
if not self.pythonpath:
|
||||||
py.test.skip("%r not found" %(version,))
|
pytest.skip("%r not found" %(version,))
|
||||||
self.picklefile = picklefile
|
self.picklefile = picklefile
|
||||||
def dumps(self, obj):
|
def dumps(self, obj):
|
||||||
dumpfile = self.picklefile.dirpath("dump.py")
|
dumpfile = self.picklefile.dirpath("dump.py")
|
||||||
|
|
|
@ -6,7 +6,7 @@ Parametrizing tests
|
||||||
|
|
||||||
.. currentmodule:: _pytest.python
|
.. currentmodule:: _pytest.python
|
||||||
|
|
||||||
py.test allows to easily parametrize test functions.
|
``pytest`` allows to easily parametrize test functions.
|
||||||
For basic docs, see :ref:`parametrize-basics`.
|
For basic docs, see :ref:`parametrize-basics`.
|
||||||
|
|
||||||
In the following we provide some examples using
|
In the following we provide some examples using
|
||||||
|
|
|
@ -10,7 +10,7 @@ You can set the :confval:`norecursedirs` option in an ini-file, for example your
|
||||||
[pytest]
|
[pytest]
|
||||||
norecursedirs = .svn _build tmp*
|
norecursedirs = .svn _build tmp*
|
||||||
|
|
||||||
This would tell py.test to not recurse into typical subversion or sphinx-build directories or into any ``tmp`` prefixed directory.
|
This would tell ``pytest`` to not recurse into typical subversion or sphinx-build directories or into any ``tmp`` prefixed directory.
|
||||||
|
|
||||||
.. _`change naming conventions`:
|
.. _`change naming conventions`:
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ the :confval:`python_files`, :confval:`python_classes` and
|
||||||
python_classes=Check
|
python_classes=Check
|
||||||
python_functions=check
|
python_functions=check
|
||||||
|
|
||||||
This would make py.test look for ``check_`` prefixes in
|
This would make ``pytest`` look for ``check_`` prefixes in
|
||||||
Python filenames, ``Check`` prefixes in classes and ``check`` prefixes
|
Python filenames, ``Check`` prefixes in classes and ``check`` prefixes
|
||||||
in functions and classes. For example, if we have::
|
in functions and classes. For example, if we have::
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ then the test collection looks like this::
|
||||||
Interpreting cmdline arguments as Python packages
|
Interpreting cmdline arguments as Python packages
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
|
|
||||||
You can use the ``--pyargs`` option to make py.test try
|
You can use the ``--pyargs`` option to make ``pytest`` try
|
||||||
interpreting arguments as python package names, deriving
|
interpreting arguments as python package names, deriving
|
||||||
their file system path and then running the test. For
|
their file system path and then running the test. For
|
||||||
example if you have unittest2 installed you can type::
|
example if you have unittest2 installed you can type::
|
||||||
|
@ -104,7 +104,7 @@ customizing test collection to find all .py files
|
||||||
|
|
||||||
.. regendoc:wipe
|
.. regendoc:wipe
|
||||||
|
|
||||||
You can easily instruct py.test to discover tests from every python file::
|
You can easily instruct ``pytest`` to discover tests from every python file::
|
||||||
|
|
||||||
|
|
||||||
# content of pytest.ini
|
# content of pytest.ini
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
.. _`tbreportdemo`:
|
.. _`tbreportdemo`:
|
||||||
|
|
||||||
Demo of Python failure reports with py.test
|
Demo of Python failure reports with pytest
|
||||||
==================================================
|
==================================================
|
||||||
|
|
||||||
Here is a nice run of several tens of failures
|
Here is a nice run of several tens of failures
|
||||||
and how py.test presents things (unfortunately
|
and how ``pytest`` presents things (unfortunately
|
||||||
not showing the nice colors here in the HTML that you
|
not showing the nice colors here in the HTML that you
|
||||||
get on the terminal - we are working on that):
|
get on the terminal - we are working on that):
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ Example::
|
||||||
def test_something():
|
def test_something():
|
||||||
checkconfig(42)
|
checkconfig(42)
|
||||||
|
|
||||||
The ``__tracebackhide__`` setting influences py.test showing
|
The ``__tracebackhide__`` setting influences ``pytest`` showing
|
||||||
of tracebacks: the ``checkconfig`` function will not be shown
|
of tracebacks: the ``checkconfig`` function will not be shown
|
||||||
unless the ``--fulltrace`` command line option is specified.
|
unless the ``--fulltrace`` command line option is specified.
|
||||||
Let's run our little function::
|
Let's run our little function::
|
||||||
|
@ -210,7 +210,7 @@ Let's run our little function::
|
||||||
test_checkconfig.py:8: Failed
|
test_checkconfig.py:8: Failed
|
||||||
1 failed in 0.01 seconds
|
1 failed in 0.01 seconds
|
||||||
|
|
||||||
Detect if running from within a py.test run
|
Detect if running from within a pytest run
|
||||||
--------------------------------------------------------------
|
--------------------------------------------------------------
|
||||||
|
|
||||||
.. regendoc:wipe
|
.. regendoc:wipe
|
||||||
|
@ -245,7 +245,7 @@ Adding info to test report header
|
||||||
|
|
||||||
.. regendoc:wipe
|
.. regendoc:wipe
|
||||||
|
|
||||||
It's easy to present extra information in a py.test run::
|
It's easy to present extra information in a ``pytest`` run::
|
||||||
|
|
||||||
# content of conftest.py
|
# content of conftest.py
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,20 @@ Some Issues and Questions
|
||||||
On naming, nosetests, licensing and magic
|
On naming, nosetests, licensing and magic
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|
||||||
How does py.test relate to nose and unittest?
|
How does pytest relate to nose and unittest?
|
||||||
+++++++++++++++++++++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
py.test and nose_ share basic philosophy when it comes
|
``pytest`` and nose_ share basic philosophy when it comes
|
||||||
to running and writing Python tests. In fact, you can run many tests
|
to running and writing Python tests. In fact, you can run many tests
|
||||||
written for nose with py.test. nose_ was originally created
|
written for nose with ``pytest``. nose_ was originally created
|
||||||
as a clone of ``py.test`` when py.test was in the ``0.8`` release
|
as a clone of ``pytest`` when ``pytest`` was in the ``0.8`` release
|
||||||
cycle. Note that starting with pytest-2.0 support for running unittest
|
cycle. Note that starting with pytest-2.0 support for running unittest
|
||||||
test suites is majorly improved.
|
test suites is majorly improved.
|
||||||
|
|
||||||
how does py.test relate to twisted's trial?
|
how does pytest relate to twisted's trial?
|
||||||
++++++++++++++++++++++++++++++++++++++++++++++
|
++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
Since some time py.test has builtin support for supporting tests
|
Since some time ``pytest`` has builtin support for supporting tests
|
||||||
written using trial. It does not itself start a reactor, however,
|
written using trial. It does not itself start a reactor, however,
|
||||||
and does not handle Deferreds returned from a test in pytest style.
|
and does not handle Deferreds returned from a test in pytest style.
|
||||||
If you are using trial's unittest.TestCase chances are that you can
|
If you are using trial's unittest.TestCase chances are that you can
|
||||||
|
@ -34,7 +34,7 @@ there also is a dedicated `pytest-twisted
|
||||||
return deferreds from pytest-style tests, allowing to use
|
return deferreds from pytest-style tests, allowing to use
|
||||||
:ref:`fixtures` and other features.
|
:ref:`fixtures` and other features.
|
||||||
|
|
||||||
how does py.test work with Django?
|
how does pytest work with Django?
|
||||||
++++++++++++++++++++++++++++++++++++++++++++++
|
++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
In 2012, some work is going into the `pytest-django plugin <http://pypi.python.org/pypi/pytest-django>`_. It substitutes the usage of Django's
|
In 2012, some work is going into the `pytest-django plugin <http://pypi.python.org/pypi/pytest-django>`_. It substitutes the usage of Django's
|
||||||
|
@ -44,15 +44,15 @@ are not available from Django directly.
|
||||||
.. _features: features.html
|
.. _features: features.html
|
||||||
|
|
||||||
|
|
||||||
What's this "magic" with py.test? (historic notes)
|
What's this "magic" with pytest? (historic notes)
|
||||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
Around 2007 (version ``0.8``) some people thought that py.test
|
Around 2007 (version ``0.8``) some people thought that ``pytest``
|
||||||
was using too much "magic". It had been part of the `pylib`_ which
|
was using too much "magic". It had been part of the `pylib`_ which
|
||||||
contains a lot of unreleated python library code. Around 2010 there
|
contains a lot of unreleated python library code. Around 2010 there
|
||||||
was a major cleanup refactoring, which removed unused or deprecated code
|
was a major cleanup refactoring, which removed unused or deprecated code
|
||||||
and resulted in the new ``pytest`` PyPI package which strictly contains
|
and resulted in the new ``pytest`` PyPI package which strictly contains
|
||||||
only test-related code. This relese also brought a complete pluginification
|
only test-related code. This release also brought a complete pluginification
|
||||||
such that the core is around 300 lines of code and everything else is
|
such that the core is around 300 lines of code and everything else is
|
||||||
implemented in plugins. Thus ``pytest`` today is a small, universally runnable
|
implemented in plugins. Thus ``pytest`` today is a small, universally runnable
|
||||||
and customizable testing framework for Python. Note, however, that
|
and customizable testing framework for Python. Note, however, that
|
||||||
|
@ -60,15 +60,15 @@ and customizable testing framework for Python. Note, however, that
|
||||||
thus likely not something for Python beginners.
|
thus likely not something for Python beginners.
|
||||||
|
|
||||||
A second "magic" issue was the assert statement debugging feature.
|
A second "magic" issue was the assert statement debugging feature.
|
||||||
Nowadays, py.test explicitely rewrites assert statements in test modules
|
Nowadays, ``pytest`` explicitely rewrites assert statements in test modules
|
||||||
in order to provide more useful :ref:`assert feedback <assertfeedback>`.
|
in order to provide more useful :ref:`assert feedback <assertfeedback>`.
|
||||||
This completely avoids previous issues of confusing assertion-reporting.
|
This completely avoids previous issues of confusing assertion-reporting.
|
||||||
It also means, that you can use Python's ``-O`` optimization without loosing
|
It also means, that you can use Python's ``-O`` optimization without loosing
|
||||||
assertions in test modules.
|
assertions in test modules.
|
||||||
|
|
||||||
py.test contains a second mostly obsolete assert debugging technique,
|
``pytest`` contains a second, mostly obsolete, assert debugging technique,
|
||||||
invoked via ``--assert=reinterpret``, activated by default on
|
invoked via ``--assert=reinterpret``, activated by default on
|
||||||
Python-2.5: When an ``assert`` statement fails, py.test re-interprets
|
Python-2.5: When an ``assert`` statement fails, ``pytest`` re-interprets
|
||||||
the expression part to show intermediate values. This technique suffers
|
the expression part to show intermediate values. This technique suffers
|
||||||
from a caveat that the rewriting does not: If your expression has side
|
from a caveat that the rewriting does not: If your expression has side
|
||||||
effects (better to avoid them anyway!) the intermediate values may not
|
effects (better to avoid them anyway!) the intermediate values may not
|
||||||
|
@ -85,7 +85,7 @@ You can also turn off all assertion interaction using the
|
||||||
Why a ``py.test`` instead of a ``pytest`` command?
|
Why a ``py.test`` instead of a ``pytest`` command?
|
||||||
++++++++++++++++++++++++++++++++++++++++++++++++++
|
++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
Some of the reasons are historic, others are practical. ``py.test``
|
Some of the reasons are historic, others are practical. ``pytest``
|
||||||
used to be part of the ``py`` package which provided several developer
|
used to be part of the ``py`` package which provided several developer
|
||||||
utilities, all starting with ``py.<TAB>``, thus providing nice
|
utilities, all starting with ``py.<TAB>``, thus providing nice
|
||||||
TAB-completion. If
|
TAB-completion. If
|
||||||
|
@ -146,10 +146,10 @@ implement the `parametrization scheme of your choice`_.
|
||||||
.. _`pytest_generate_tests`: test/funcargs.html#parametrizing-tests
|
.. _`pytest_generate_tests`: test/funcargs.html#parametrizing-tests
|
||||||
.. _`parametrization scheme of your choice`: http://tetamap.wordpress.com/2009/05/13/parametrizing-python-tests-generalized/
|
.. _`parametrization scheme of your choice`: http://tetamap.wordpress.com/2009/05/13/parametrizing-python-tests-generalized/
|
||||||
|
|
||||||
py.test interaction with other packages
|
pytest interaction with other packages
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
Issues with py.test, multiprocess and setuptools?
|
Issues with pytest, multiprocess and setuptools?
|
||||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
On windows the multiprocess package will instantiate sub processes
|
On windows the multiprocess package will instantiate sub processes
|
||||||
|
|
|
@ -99,7 +99,7 @@ marked ``smtp`` fixture function. Running the test looks like this::
|
||||||
In the failure traceback we see that the test function was called with a
|
In the failure traceback we see that the test function was called with a
|
||||||
``smtp`` argument, the ``smtplib.SMTP()`` instance created by the fixture
|
``smtp`` argument, the ``smtplib.SMTP()`` instance created by the fixture
|
||||||
function. The test function fails on our deliberate ``assert 0``. Here is
|
function. The test function fails on our deliberate ``assert 0``. Here is
|
||||||
an exact protocol of how py.test comes to call the test function this way:
|
the exact protocol used by ``pytest`` to call the test function this way:
|
||||||
|
|
||||||
1. pytest :ref:`finds <test discovery>` the ``test_ehlo`` because
|
1. pytest :ref:`finds <test discovery>` the ``test_ehlo`` because
|
||||||
of the ``test_`` prefix. The test function needs a function argument
|
of the ``test_`` prefix. The test function needs a function argument
|
||||||
|
|
|
@ -23,7 +23,7 @@ Installation options::
|
||||||
To check your installation has installed the correct version::
|
To check your installation has installed the correct version::
|
||||||
|
|
||||||
$ py.test --version
|
$ py.test --version
|
||||||
This is py.test version 2.5.1, imported from /home/hpk/p/pytest/.tox/regen/local/lib/python2.7/site-packages/pytest.pyc
|
This is pytest version 2.5.1, imported from /home/hpk/p/pytest/.tox/regen/local/lib/python2.7/site-packages/pytest.pyc
|
||||||
|
|
||||||
If you get an error checkout :ref:`installation issues`.
|
If you get an error checkout :ref:`installation issues`.
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ That's it. You can execute the test function now::
|
||||||
test_sample.py:5: AssertionError
|
test_sample.py:5: AssertionError
|
||||||
========================= 1 failed in 0.01 seconds =========================
|
========================= 1 failed in 0.01 seconds =========================
|
||||||
|
|
||||||
py.test found the ``test_answer`` function by following :ref:`standard test discovery rules <test discovery>`, basically detecting the ``test_`` prefixes. We got a failure report because our little ``func(3)`` call did not return ``5``.
|
``pytest`` found the ``test_answer`` function by following :ref:`standard test discovery rules <test discovery>`, basically detecting the ``test_`` prefixes. We got a failure report because our little ``func(3)`` call did not return ``5``.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ resources, for example a unique temporary directory::
|
||||||
assert 0
|
assert 0
|
||||||
|
|
||||||
We list the name ``tmpdir`` in the test function signature and
|
We list the name ``tmpdir`` in the test function signature and
|
||||||
py.test will lookup and call a fixture factory to create the resource
|
``pytest`` will lookup and call a fixture factory to create the resource
|
||||||
before performing the test function call. Let's just run it::
|
before performing the test function call. Let's just run it::
|
||||||
|
|
||||||
$ py.test -q test_tmpdir.py
|
$ py.test -q test_tmpdir.py
|
||||||
|
@ -186,7 +186,7 @@ Here are a few suggestions where to go next:
|
||||||
* :ref:`cmdline` for command line invocation examples
|
* :ref:`cmdline` for command line invocation examples
|
||||||
* :ref:`good practises <goodpractises>` for virtualenv, test layout, genscript support
|
* :ref:`good practises <goodpractises>` for virtualenv, test layout, genscript support
|
||||||
* :ref:`fixtures` for providing a functional baseline to your tests
|
* :ref:`fixtures` for providing a functional baseline to your tests
|
||||||
* :ref:`apiref` for documentation and examples on using py.test
|
* :ref:`apiref` for documentation and examples on using ``pytest``
|
||||||
* :ref:`plugins` managing and writing plugins
|
* :ref:`plugins` managing and writing plugins
|
||||||
|
|
||||||
.. _`installation issues`:
|
.. _`installation issues`:
|
||||||
|
@ -221,7 +221,7 @@ py.test not found on Windows despite installation?
|
||||||
- **Jython2.5.1 on Windows XP**: `Jython does not create command line launchers`_
|
- **Jython2.5.1 on Windows XP**: `Jython does not create command line launchers`_
|
||||||
so ``py.test`` will not work correctly. You may install py.test on
|
so ``py.test`` will not work correctly. You may install py.test on
|
||||||
CPython and type ``py.test --genscript=mytest`` and then use
|
CPython and type ``py.test --genscript=mytest`` and then use
|
||||||
``jython mytest`` to run py.test for your tests to run with Jython.
|
``jython mytest`` to run your tests with Jython using ``pytest``.
|
||||||
|
|
||||||
:ref:`examples` for more complex examples
|
:ref:`examples` for more complex examples
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ virtual environment.
|
||||||
Choosing a test layout / import rules
|
Choosing a test layout / import rules
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
|
||||||
py.test supports two common test layouts:
|
``pytest`` supports two common test layouts:
|
||||||
|
|
||||||
* putting tests into an extra directory outside your actual application
|
* putting tests into an extra directory outside your actual application
|
||||||
code, useful if you have many functional tests or for other reasons
|
code, useful if you have many functional tests or for other reasons
|
||||||
|
@ -107,7 +107,7 @@ required configurations.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
If py.test finds a "a/b/test_module.py" test file while
|
If ``pytest`` finds a "a/b/test_module.py" test file while
|
||||||
recursing into the filesystem it determines the import name
|
recursing into the filesystem it determines the import name
|
||||||
as follows:
|
as follows:
|
||||||
|
|
||||||
|
@ -155,17 +155,17 @@ to create a JUnitXML file that Jenkins_ can pick up and generate reports.
|
||||||
.. _standalone:
|
.. _standalone:
|
||||||
.. _`genscript method`:
|
.. _`genscript method`:
|
||||||
|
|
||||||
Create a py.test standalone script
|
Create a pytest standalone script
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
If you are a maintainer or application developer and want people
|
If you are a maintainer or application developer and want people
|
||||||
who don't deal with python much to easily run tests you may generate
|
who don't deal with python much to easily run tests you may generate
|
||||||
a standalone "py.test" script::
|
a standalone ``pytest`` script::
|
||||||
|
|
||||||
py.test --genscript=runtests.py
|
py.test --genscript=runtests.py
|
||||||
|
|
||||||
This generates a ``runtests.py`` script which is a fully functional basic
|
This generates a ``runtests.py`` script which is a fully functional basic
|
||||||
``py.test`` script, running unchanged under Python2 and Python3.
|
``pytest`` script, running unchanged under Python2 and Python3.
|
||||||
You can tell people to download the script and then e.g. run it like this::
|
You can tell people to download the script and then e.g. run it like this::
|
||||||
|
|
||||||
python runtests.py
|
python runtests.py
|
||||||
|
@ -176,7 +176,7 @@ Integrating with distutils / ``python setup.py test``
|
||||||
|
|
||||||
You can integrate test runs into your distutils or
|
You can integrate test runs into your distutils or
|
||||||
setuptools based project. Use the `genscript method`_
|
setuptools based project. Use the `genscript method`_
|
||||||
to generate a standalone py.test script::
|
to generate a standalone ``pytest`` script::
|
||||||
|
|
||||||
py.test --genscript=runtests.py
|
py.test --genscript=runtests.py
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ If you now type::
|
||||||
python setup.py test
|
python setup.py test
|
||||||
|
|
||||||
this will execute your tests using ``runtests.py``. As this is a
|
this will execute your tests using ``runtests.py``. As this is a
|
||||||
standalone version of ``py.test`` no prior installation whatsoever is
|
standalone version of ``pytest`` no prior installation whatsoever is
|
||||||
required for calling the test command. You can also pass additional
|
required for calling the test command. You can also pass additional
|
||||||
arguments to the subprocess-calls such as your test directory or other
|
arguments to the subprocess-calls such as your test directory or other
|
||||||
options.
|
options.
|
||||||
|
@ -244,7 +244,7 @@ Now if you run::
|
||||||
|
|
||||||
python setup.py test
|
python setup.py test
|
||||||
|
|
||||||
this will download py.test if needed and then run py.test
|
this will download ``pytest`` if needed and then run your tests
|
||||||
as you would expect it to.
|
as you would expect it to.
|
||||||
|
|
||||||
.. _`test discovery`:
|
.. _`test discovery`:
|
||||||
|
@ -253,7 +253,7 @@ as you would expect it to.
|
||||||
Conventions for Python test discovery
|
Conventions for Python test discovery
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
``py.test`` implements the following standard test discovery:
|
``pytest`` implements the following standard test discovery:
|
||||||
|
|
||||||
* collection starts from the initial command line arguments
|
* collection starts from the initial command line arguments
|
||||||
which may be directories, filenames or test ids.
|
which may be directories, filenames or test ids.
|
||||||
|
@ -264,7 +264,7 @@ Conventions for Python test discovery
|
||||||
|
|
||||||
For examples of how to customize your test discovery :doc:`example/pythoncollection`.
|
For examples of how to customize your test discovery :doc:`example/pythoncollection`.
|
||||||
|
|
||||||
Within Python modules, py.test also discovers tests using the standard
|
Within Python modules, ``pytest`` also discovers tests using the standard
|
||||||
:ref:`unittest.TestCase <unittest.TestCase>` subclassing technique.
|
:ref:`unittest.TestCase <unittest.TestCase>` subclassing technique.
|
||||||
|
|
||||||
.. include:: links.inc
|
.. include:: links.inc
|
||||||
|
|
|
@ -3,7 +3,7 @@ Running tests written for nose
|
||||||
|
|
||||||
.. include:: links.inc
|
.. include:: links.inc
|
||||||
|
|
||||||
py.test has basic support for running tests written for nose_.
|
``pytest`` has basic support for running tests written for nose_.
|
||||||
|
|
||||||
.. _nosestyle:
|
.. _nosestyle:
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ After :ref:`installation` type::
|
||||||
py.test # instead of 'nosetests'
|
py.test # instead of 'nosetests'
|
||||||
|
|
||||||
and you should be able to run your nose style tests and
|
and you should be able to run your nose style tests and
|
||||||
make use of py.test's capabilities.
|
make use of pytest's capabilities.
|
||||||
|
|
||||||
Supported nose Idioms
|
Supported nose Idioms
|
||||||
----------------------
|
----------------------
|
||||||
|
|
|
@ -131,7 +131,7 @@ importantly, you can call ``metafunc.parametrize()`` to cause
|
||||||
parametrization.
|
parametrization.
|
||||||
|
|
||||||
For example, let's say we want to run a test taking string inputs which
|
For example, let's say we want to run a test taking string inputs which
|
||||||
we want to set via a new py.test command line option. Let's first write
|
we want to set via a new ``pytest`` command line option. Let's first write
|
||||||
a simple test accepting a ``stringinput`` fixture function argument::
|
a simple test accepting a ``stringinput`` fixture function argument::
|
||||||
|
|
||||||
# content of test_strings.py
|
# content of test_strings.py
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
Working with plugins and conftest files
|
Working with plugins and conftest files
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
py.test implements all aspects of configuration, collection, running and reporting by calling `well specified hooks`_. Virtually any Python module can be registered as a plugin. It can implement any number of hook functions (usually two or three) which all have a ``pytest_`` prefix, making hook functions easy to distinguish and find. There are three basic location types:
|
``pytest`` implements all aspects of configuration, collection, running and reporting by calling `well specified hooks`_. Virtually any Python module can be registered as a plugin. It can implement any number of hook functions (usually two or three) which all have a ``pytest_`` prefix, making hook functions easy to distinguish and find. There are three basic location types:
|
||||||
|
|
||||||
* `builtin plugins`_: loaded from py.test's internal ``_pytest`` directory.
|
* `builtin plugins`_: loaded from pytest's internal ``_pytest`` directory.
|
||||||
* `external plugins`_: modules discovered through `setuptools entry points`_
|
* `external plugins`_: modules discovered through `setuptools entry points`_
|
||||||
* `conftest.py plugins`_: modules auto-discovered in test directories
|
* `conftest.py plugins`_: modules auto-discovered in test directories
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ tool, for example::
|
||||||
pip install pytest-NAME
|
pip install pytest-NAME
|
||||||
pip uninstall pytest-NAME
|
pip uninstall pytest-NAME
|
||||||
|
|
||||||
If a plugin is installed, py.test automatically finds and integrates it,
|
If a plugin is installed, ``pytest`` automatically finds and integrates it,
|
||||||
there is no need to activate it. Here is a initial list of known plugins:
|
there is no need to activate it. Here is a initial list of known plugins:
|
||||||
|
|
||||||
.. _`django`: https://www.djangoproject.com/
|
.. _`django`: https://www.djangoproject.com/
|
||||||
|
@ -122,7 +122,7 @@ If you want to write a plugin, there are many real-life examples
|
||||||
you can copy from:
|
you can copy from:
|
||||||
|
|
||||||
* a custom collection example plugin: :ref:`yaml plugin`
|
* a custom collection example plugin: :ref:`yaml plugin`
|
||||||
* around 20 `builtin plugins`_ which provide py.test's own functionality
|
* around 20 `builtin plugins`_ which provide pytest's own functionality
|
||||||
* many `external plugins`_ providing additional features
|
* many `external plugins`_ providing additional features
|
||||||
|
|
||||||
All of these plugins implement the documented `well specified hooks`_
|
All of these plugins implement the documented `well specified hooks`_
|
||||||
|
@ -135,9 +135,9 @@ Making your plugin installable by others
|
||||||
|
|
||||||
If you want to make your plugin externally available, you
|
If you want to make your plugin externally available, you
|
||||||
may define a so-called entry point for your distribution so
|
may define a so-called entry point for your distribution so
|
||||||
that ``py.test`` finds your plugin module. Entry points are
|
that ``pytest`` finds your plugin module. Entry points are
|
||||||
a feature that is provided by `setuptools`_ or `Distribute`_.
|
a feature that is provided by `setuptools`_ or `Distribute`_.
|
||||||
py.test looks up the ``pytest11`` entrypoint to discover its
|
pytest looks up the ``pytest11`` entrypoint to discover its
|
||||||
plugins and you can thus make your plugin available by definig
|
plugins and you can thus make your plugin available by definig
|
||||||
it in your setuptools/distribute-based setup-invocation:
|
it in your setuptools/distribute-based setup-invocation:
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ it in your setuptools/distribute-based setup-invocation:
|
||||||
name="myproject",
|
name="myproject",
|
||||||
packages = ['myproject']
|
packages = ['myproject']
|
||||||
|
|
||||||
# the following makes a plugin available to py.test
|
# the following makes a plugin available to pytest
|
||||||
entry_points = {
|
entry_points = {
|
||||||
'pytest11': [
|
'pytest11': [
|
||||||
'name_of_plugin = myproject.pluginmodule',
|
'name_of_plugin = myproject.pluginmodule',
|
||||||
|
@ -158,7 +158,7 @@ it in your setuptools/distribute-based setup-invocation:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
If a package is installed this way, py.test will load
|
If a package is installed this way, ``pytest`` will load
|
||||||
``myproject.pluginmodule`` as a plugin which can define
|
``myproject.pluginmodule`` as a plugin which can define
|
||||||
`well specified hooks`_.
|
`well specified hooks`_.
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ If a package is installed this way, py.test will load
|
||||||
Plugin discovery order at tool startup
|
Plugin discovery order at tool startup
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
py.test loads plugin modules at tool startup in the following way:
|
``pytest`` loads plugin modules at tool startup in the following way:
|
||||||
|
|
||||||
* by loading all builtin plugins
|
* by loading all builtin plugins
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ will be loaded as well. You can also use dotted path like this::
|
||||||
|
|
||||||
pytest_plugins = "myapp.testsupport.myplugin"
|
pytest_plugins = "myapp.testsupport.myplugin"
|
||||||
|
|
||||||
which will import the specified module as a py.test plugin.
|
which will import the specified module as a ``pytest`` plugin.
|
||||||
|
|
||||||
|
|
||||||
Accessing another plugin by name
|
Accessing another plugin by name
|
||||||
|
@ -243,7 +243,7 @@ how to obtain the name of a plugin.
|
||||||
|
|
||||||
.. _`builtin plugins`:
|
.. _`builtin plugins`:
|
||||||
|
|
||||||
py.test default plugin reference
|
pytest default plugin reference
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
|
|
||||||
|
@ -277,14 +277,14 @@ in the `pytest repository <http://bitbucket.org/hpk42/pytest/>`_.
|
||||||
|
|
||||||
.. _`well specified hooks`:
|
.. _`well specified hooks`:
|
||||||
|
|
||||||
py.test hook reference
|
pytest hook reference
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
Hook specification and validation
|
Hook specification and validation
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
py.test calls hook functions to implement initialization, running,
|
``pytest`` calls hook functions to implement initialization, running,
|
||||||
test execution and reporting. When py.test loads a plugin it validates
|
test execution and reporting. When ``pytest`` loads a plugin it validates
|
||||||
that each hook function conforms to its respective hook specification.
|
that each hook function conforms to its respective hook specification.
|
||||||
Each hook function name and its argument names need to match a hook
|
Each hook function name and its argument names need to match a hook
|
||||||
specification. However, a hook function may accept *fewer* parameters
|
specification. However, a hook function may accept *fewer* parameters
|
||||||
|
@ -327,7 +327,7 @@ the reporting hook to print information about a test run.
|
||||||
Collection hooks
|
Collection hooks
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
py.test calls the following hooks for collecting files and directories:
|
``pytest`` calls the following hooks for collecting files and directories:
|
||||||
|
|
||||||
.. autofunction:: pytest_ignore_collect
|
.. autofunction:: pytest_ignore_collect
|
||||||
.. autofunction:: pytest_collect_directory
|
.. autofunction:: pytest_collect_directory
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
Project examples
|
Project examples
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
Here are some examples of projects using py.test (please send notes via :ref:`contact`):
|
Here are some examples of projects using ``pytest`` (please send notes via :ref:`contact`):
|
||||||
|
|
||||||
* `PyPy <http://pypy.org>`_, Python with a JIT compiler, running over
|
* `PyPy <http://pypy.org>`_, Python with a JIT compiler, running over
|
||||||
`21000 tests <http://buildbot.pypy.org/summary?branch=%3Ctrunk%3E>`_
|
`21000 tests <http://buildbot.pypy.org/summary?branch=%3Ctrunk%3E>`_
|
||||||
|
@ -60,7 +60,7 @@ Here are some examples of projects using py.test (please send notes via :ref:`co
|
||||||
* `pytest-localserver <https://bitbucket.org/basti/pytest-localserver/>`_ a plugin for pytest that provides a httpserver and smtpserver
|
* `pytest-localserver <https://bitbucket.org/basti/pytest-localserver/>`_ a plugin for pytest that provides a httpserver and smtpserver
|
||||||
* `pytest-monkeyplus <http://pypi.python.org/pypi/pytest-monkeyplus/>`_ a plugin that extends monkeypatch
|
* `pytest-monkeyplus <http://pypi.python.org/pypi/pytest-monkeyplus/>`_ a plugin that extends monkeypatch
|
||||||
|
|
||||||
These projects help integrate py.test into other Python frameworks:
|
These projects help integrate ``pytest`` into other Python frameworks:
|
||||||
|
|
||||||
* `pytest-django <http://pypi.python.org/pypi/pytest-django/>`_ for Django
|
* `pytest-django <http://pypi.python.org/pypi/pytest-django/>`_ for Django
|
||||||
* `zope.pytest <http://packages.python.org/zope.pytest/>`_ for Zope and Grok
|
* `zope.pytest <http://packages.python.org/zope.pytest/>`_ for Zope and Grok
|
||||||
|
@ -68,7 +68,7 @@ These projects help integrate py.test into other Python frameworks:
|
||||||
* There is `some work <https://github.com/Kotti/Kotti/blob/master/kotti/testing.py>`_ underway for Kotti, a CMS built in Pyramid/Pylons
|
* There is `some work <https://github.com/Kotti/Kotti/blob/master/kotti/testing.py>`_ underway for Kotti, a CMS built in Pyramid/Pylons
|
||||||
|
|
||||||
|
|
||||||
Some organisations using py.test
|
Some organisations using pytest
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
* `Square Kilometre Array, Cape Town <http://ska.ac.za/>`_
|
* `Square Kilometre Array, Cape Town <http://ska.ac.za/>`_
|
||||||
|
|
|
@ -14,7 +14,7 @@ A *skip* means that you expect your test to pass unless the environment
|
||||||
And *xfail* means that your test can run but you expect it to fail
|
And *xfail* means that your test can run but you expect it to fail
|
||||||
because there is an implementation problem.
|
because there is an implementation problem.
|
||||||
|
|
||||||
py.test counts and lists *skip* and *xfail* tests separately. Detailed
|
``pytest`` counts and lists *skip* and *xfail* tests separately. Detailed
|
||||||
information about skipped/xfailed tests is not shown by default to avoid
|
information about skipped/xfailed tests is not shown by default to avoid
|
||||||
cluttering the output. You can use the ``-r`` option to see details
|
cluttering the output. You can use the ``-r`` option to see details
|
||||||
corresponding to the "short" letters shown in the test progress::
|
corresponding to the "short" letters shown in the test progress::
|
||||||
|
@ -104,7 +104,7 @@ you can set the ``pytestmark`` attribute of a class::
|
||||||
"will not be setup or run under 'win32' platform"
|
"will not be setup or run under 'win32' platform"
|
||||||
|
|
||||||
As with the class-decorator, the ``pytestmark`` special name tells
|
As with the class-decorator, the ``pytestmark`` special name tells
|
||||||
py.test to apply it to each test function in the class.
|
``pytest`` to apply it to each test function in the class.
|
||||||
|
|
||||||
If you want to skip all test functions of a module, you must use
|
If you want to skip all test functions of a module, you must use
|
||||||
the ``pytestmark`` name on the global level::
|
the ``pytestmark`` name on the global level::
|
||||||
|
@ -255,7 +255,7 @@ because markers can then be freely imported between test modules.
|
||||||
With strings you need to import not only the marker but all variables
|
With strings you need to import not only the marker but all variables
|
||||||
everything used by the marker, which violates encapsulation.
|
everything used by the marker, which violates encapsulation.
|
||||||
|
|
||||||
The reason for specifying the condition as a string was that py.test can
|
The reason for specifying the condition as a string was that ``pytest`` can
|
||||||
report a summary of skip conditions based purely on the condition string.
|
report a summary of skip conditions based purely on the condition string.
|
||||||
With conditions as booleans you are required to specify a ``reason`` string.
|
With conditions as booleans you are required to specify a ``reason`` string.
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ Test parametrization:
|
||||||
|
|
||||||
Assertion introspection:
|
Assertion introspection:
|
||||||
|
|
||||||
- `(07/2011) Behind the scenes of py.test's new assertion rewriting
|
- `(07/2011) Behind the scenes of pytest's new assertion rewriting
|
||||||
<http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_
|
<http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_
|
||||||
|
|
||||||
Distributed testing:
|
Distributed testing:
|
||||||
|
@ -48,11 +48,11 @@ Distributed testing:
|
||||||
|
|
||||||
Plugin specific examples:
|
Plugin specific examples:
|
||||||
|
|
||||||
- `skipping slow tests by default in py.test`_ (blog entry)
|
- `skipping slow tests by default in pytest`_ (blog entry)
|
||||||
|
|
||||||
- `many examples in the docs for plugins`_
|
- `many examples in the docs for plugins`_
|
||||||
|
|
||||||
.. _`skipping slow tests by default in py.test`: http://bruynooghe.blogspot.com/2009/12/skipping-slow-test-by-default-in-pytest.html
|
.. _`skipping slow tests by default in pytest`: http://bruynooghe.blogspot.com/2009/12/skipping-slow-test-by-default-in-pytest.html
|
||||||
.. _`many examples in the docs for plugins`: plugin/index.html
|
.. _`many examples in the docs for plugins`: plugin/index.html
|
||||||
.. _`monkeypatch plugin`: plugin/monkeypatch.html
|
.. _`monkeypatch plugin`: plugin/monkeypatch.html
|
||||||
.. _`application setup in test functions with funcargs`: funcargs.html#appsetup
|
.. _`application setup in test functions with funcargs`: funcargs.html#appsetup
|
||||||
|
@ -69,14 +69,14 @@ Older conference talks and tutorials
|
||||||
- `ep2009-rapidtesting.pdf`_ tutorial slides (July 2009):
|
- `ep2009-rapidtesting.pdf`_ tutorial slides (July 2009):
|
||||||
|
|
||||||
- testing terminology
|
- testing terminology
|
||||||
- basic py.test usage, file system layout
|
- basic pytest usage, file system layout
|
||||||
- test function arguments (funcargs_) and test fixtures
|
- test function arguments (funcargs_) and test fixtures
|
||||||
- existing plugins
|
- existing plugins
|
||||||
- distributed testing
|
- distributed testing
|
||||||
|
|
||||||
- `ep2009-pytest.pdf`_ 60 minute py.test talk, highlighting unique features and a roadmap (July 2009)
|
- `ep2009-pytest.pdf`_ 60 minute pytest talk, highlighting unique features and a roadmap (July 2009)
|
||||||
|
|
||||||
- `pycon2009-pytest-introduction.zip`_ slides and files, extended version of py.test basic introduction, discusses more options, also introduces old-style xUnit setup, looponfailing and other features.
|
- `pycon2009-pytest-introduction.zip`_ slides and files, extended version of pytest basic introduction, discusses more options, also introduces old-style xUnit setup, looponfailing and other features.
|
||||||
|
|
||||||
- `pycon2009-pytest-advanced.pdf`_ contain a slightly older version of funcargs and distributed testing, compared to the EuroPython 2009 slides.
|
- `pycon2009-pytest-advanced.pdf`_ contain a slightly older version of funcargs and distributed testing, compared to the EuroPython 2009 slides.
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ writing conftest.py files
|
||||||
You may put conftest.py files containing project-specific
|
You may put conftest.py files containing project-specific
|
||||||
configuration in your project's root directory, it's usually
|
configuration in your project's root directory, it's usually
|
||||||
best to put it just into the same directory level as your
|
best to put it just into the same directory level as your
|
||||||
topmost ``__init__.py``. In fact, ``py.test`` performs
|
topmost ``__init__.py``. In fact, ``pytest`` performs
|
||||||
an "upwards" search starting from the directory that you specify
|
an "upwards" search starting from the directory that you specify
|
||||||
to be tested and will lookup configuration values right-to-left.
|
to be tested and will lookup configuration values right-to-left.
|
||||||
You may have options that reside e.g. in your home directory
|
You may have options that reside e.g. in your home directory
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=======================================
|
=======================================
|
||||||
py.test documentation index
|
pytest documentation index
|
||||||
=======================================
|
=======================================
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ customize_: configuration, customization, extensions
|
||||||
|
|
||||||
changelog_: history of changes covering last releases
|
changelog_: history of changes covering last releases
|
||||||
|
|
||||||
**Continuous Integration of py.test's own tests and plugins with Hudson**:
|
**Continuous Integration of pytest's own tests and plugins with Hudson**:
|
||||||
|
|
||||||
`http://hudson.testrun.org/view/pytest`_
|
`http://hudson.testrun.org/view/pytest`_
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
Mission
|
Mission
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
py.test strives to make testing a fun and no-boilerplate effort.
|
``pytest`` strives to make testing a fun and no-boilerplate effort.
|
||||||
|
|
||||||
The tool is distributed as part of the `py` package which contains supporting APIs that
|
The tool is distributed as a `pytest` package. Its project independent
|
||||||
are also usable independently. The project independent ``py.test`` command line tool helps you to:
|
``py.test`` command line tool helps you to:
|
||||||
|
|
||||||
* rapidly collect and run tests
|
* rapidly collect and run tests
|
||||||
* run unit- or doctests, functional or integration tests
|
* run unit- or doctests, functional or integration tests
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pytest_django plugin (EXTERNAL)
|
pytest_django plugin (EXTERNAL)
|
||||||
==========================================
|
==========================================
|
||||||
|
|
||||||
pytest_django is a plugin for py.test that provides a set of useful tools for testing Django applications, checkout Ben Firshman's `pytest_django github page`_.
|
pytest_django is a plugin for ``pytest`` that provides a set of useful tools for testing Django applications, checkout Ben Firshman's `pytest_django github page`_.
|
||||||
|
|
||||||
.. _`pytest_django github page`: http://github.com/bfirsh/pytest_django/tree/master
|
.. _`pytest_django github page`: http://github.com/bfirsh/pytest_django/tree/master
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ command line options
|
||||||
|
|
||||||
|
|
||||||
``--genscript=path``
|
``--genscript=path``
|
||||||
create standalone py.test script at given target path.
|
create standalone ``pytest`` script at given target path.
|
||||||
|
|
||||||
Start improving this plugin in 30 seconds
|
Start improving this plugin in 30 seconds
|
||||||
=========================================
|
=========================================
|
||||||
|
@ -21,7 +21,7 @@ Start improving this plugin in 30 seconds
|
||||||
|
|
||||||
1. Download `pytest_genscript.py`_ plugin source code
|
1. Download `pytest_genscript.py`_ plugin source code
|
||||||
2. put it somewhere as ``pytest_genscript.py`` into your import path
|
2. put it somewhere as ``pytest_genscript.py`` into your import path
|
||||||
3. a subsequent ``py.test`` run will use your local version
|
3. a subsequent ``pytest`` run will use your local version
|
||||||
|
|
||||||
Checkout customize_, other plugins_ or `get in contact`_.
|
Checkout customize_, other plugins_ or `get in contact`_.
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ Start improving this plugin in 30 seconds
|
||||||
|
|
||||||
1. Download `pytest_helpconfig.py`_ plugin source code
|
1. Download `pytest_helpconfig.py`_ plugin source code
|
||||||
2. put it somewhere as ``pytest_helpconfig.py`` into your import path
|
2. put it somewhere as ``pytest_helpconfig.py`` into your import path
|
||||||
3. a subsequent ``py.test`` run will use your local version
|
3. a subsequent ``pytest`` run will use your local version
|
||||||
|
|
||||||
Checkout customize_, other plugins_ or `get in contact`_.
|
Checkout customize_, other plugins_ or `get in contact`_.
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
.. _`capturelog`: capturelog.html
|
.. _`capturelog`: capturelog.html
|
||||||
.. _`junitxml`: junitxml.html
|
.. _`junitxml`: junitxml.html
|
||||||
.. _`pytest_skipping.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_skipping.py
|
.. _`pytest_skipping.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_skipping.py
|
||||||
.. _`checkout the py.test development version`: ../../install.html#checkout
|
.. _`checkout the pytest development version`: ../../install.html#checkout
|
||||||
.. _`pytest_helpconfig.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_helpconfig.py
|
.. _`pytest_helpconfig.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_helpconfig.py
|
||||||
.. _`oejskit`: oejskit.html
|
.. _`oejskit`: oejskit.html
|
||||||
.. _`doctest`: doctest.html
|
.. _`doctest`: doctest.html
|
||||||
|
|
|
@ -7,7 +7,7 @@ nose-compatibility plugin: allow to run nose test suites natively.
|
||||||
:local:
|
:local:
|
||||||
|
|
||||||
This is an experimental plugin for allowing to run tests written
|
This is an experimental plugin for allowing to run tests written
|
||||||
in 'nosetests style with py.test.
|
in 'nosetests' style with ``pytest``.
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-------------
|
-------------
|
||||||
|
@ -17,7 +17,7 @@ type::
|
||||||
py.test # instead of 'nosetests'
|
py.test # instead of 'nosetests'
|
||||||
|
|
||||||
and you should be able to run nose style tests and at the same
|
and you should be able to run nose style tests and at the same
|
||||||
time can make full use of py.test's capabilities.
|
time can make full use of pytest's capabilities.
|
||||||
|
|
||||||
Supported nose Idioms
|
Supported nose Idioms
|
||||||
----------------------
|
----------------------
|
||||||
|
@ -40,7 +40,7 @@ If you find other issues or have suggestions please run::
|
||||||
|
|
||||||
py.test --pastebin=all
|
py.test --pastebin=all
|
||||||
|
|
||||||
and send the resulting URL to a py.test contact channel,
|
and send the resulting URL to a ``pytest`` contact channel,
|
||||||
at best to the mailing list.
|
at best to the mailing list.
|
||||||
|
|
||||||
Start improving this plugin in 30 seconds
|
Start improving this plugin in 30 seconds
|
||||||
|
@ -49,7 +49,7 @@ Start improving this plugin in 30 seconds
|
||||||
|
|
||||||
1. Download `pytest_nose.py`_ plugin source code
|
1. Download `pytest_nose.py`_ plugin source code
|
||||||
2. put it somewhere as ``pytest_nose.py`` into your import path
|
2. put it somewhere as ``pytest_nose.py`` into your import path
|
||||||
3. a subsequent ``py.test`` run will use your local version
|
3. a subsequent ``pytest`` run will use your local version
|
||||||
|
|
||||||
Checkout customize_, other plugins_ or `get in contact`_.
|
Checkout customize_, other plugins_ or `get in contact`_.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pytest_oejskit plugin (EXTERNAL)
|
pytest_oejskit plugin (EXTERNAL)
|
||||||
==========================================
|
==========================================
|
||||||
|
|
||||||
The `oejskit`_ offers a py.test plugin for running Javascript tests in life browsers. Running inside the browsers comes with some speed cost, on the other hand it means for example the code is tested against the real-word DOM implementations.
|
The `oejskit`_ offers a ``pytest`` plugin for running Javascript tests in live browsers. Running inside the browsers comes with some speed cost, on the other hand it means for example the code is tested against the real-word DOM implementations.
|
||||||
The approach enables to write integration tests such that the JavaScript code is tested against server-side Python code mocked as necessary. Any server-side framework that can already be exposed through WSGI (or for which a subset of WSGI can be written to accommodate the jskit own needs) can play along.
|
The approach enables to write integration tests such that the JavaScript code is tested against server-side Python code mocked as necessary. Any server-side framework that can already be exposed through WSGI (or for which a subset of WSGI can be written to accommodate the jskit own needs) can play along.
|
||||||
|
|
||||||
For more info and download please visit the `oejskit PyPI`_ page.
|
For more info and download please visit the `oejskit PyPI`_ page.
|
||||||
|
|
|
@ -33,7 +33,7 @@ Start improving this plugin in 30 seconds
|
||||||
|
|
||||||
1. Download `pytest_terminal.py`_ plugin source code
|
1. Download `pytest_terminal.py`_ plugin source code
|
||||||
2. put it somewhere as ``pytest_terminal.py`` into your import path
|
2. put it somewhere as ``pytest_terminal.py`` into your import path
|
||||||
3. a subsequent ``py.test`` run will use your local version
|
3. a subsequent ``pytest`` run will use your local version
|
||||||
|
|
||||||
Checkout customize_, other plugins_ or `get in contact`_.
|
Checkout customize_, other plugins_ or `get in contact`_.
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,13 @@ loop on failing tests, distribute test runs to CPUs and hosts.
|
||||||
.. contents::
|
.. contents::
|
||||||
:local:
|
:local:
|
||||||
|
|
||||||
The `pytest-xdist`_ plugin extends py.test with some unique
|
The `pytest-xdist`_ plugin extends ``pytest`` with some unique
|
||||||
test execution modes:
|
test execution modes:
|
||||||
|
|
||||||
* Looponfail: run your tests repeatedly in a subprocess. After each run py.test
|
* Looponfail: run your tests repeatedly in a subprocess. After each run
|
||||||
waits until a file in your project changes and then re-runs the previously
|
``pytest`` waits until a file in your project changes and then re-runs the
|
||||||
failing tests. This is repeated until all tests pass after which again
|
previously failing tests. This is repeated until all tests pass after which
|
||||||
a full run is performed.
|
again a full run is performed.
|
||||||
|
|
||||||
* Load-balancing: if you have multiple CPUs or hosts you can use
|
* Load-balancing: if you have multiple CPUs or hosts you can use
|
||||||
those for a combined test run. This allows to speed up
|
those for a combined test run. This allows to speed up
|
||||||
|
@ -21,7 +21,7 @@ test execution modes:
|
||||||
* Multi-Platform coverage: you can specify different Python interpreters
|
* Multi-Platform coverage: you can specify different Python interpreters
|
||||||
or different platforms and run tests in parallel on all of them.
|
or different platforms and run tests in parallel on all of them.
|
||||||
|
|
||||||
Before running tests remotely, ``py.test`` efficiently synchronizes your
|
Before running tests remotely, ``pytest`` efficiently synchronizes your
|
||||||
program source code to the remote place. All test results
|
program source code to the remote place. All test results
|
||||||
are reported back and displayed to your local test session.
|
are reported back and displayed to your local test session.
|
||||||
You may specify different Python versions and interpreters.
|
You may specify different Python versions and interpreters.
|
||||||
|
@ -77,11 +77,11 @@ and send them to remote places for execution.
|
||||||
You can specify multiple ``--rsyncdir`` directories
|
You can specify multiple ``--rsyncdir`` directories
|
||||||
to be sent to the remote side.
|
to be sent to the remote side.
|
||||||
|
|
||||||
**NOTE:** For py.test to collect and send tests correctly
|
**NOTE:** For ``pytest`` to collect and send tests correctly
|
||||||
you not only need to make sure all code and tests
|
you not only need to make sure all code and tests
|
||||||
directories are rsynced, but that any test (sub) directory
|
directories are rsynced, but that any test (sub) directory
|
||||||
also has an ``__init__.py`` file because internally
|
also has an ``__init__.py`` file because internally
|
||||||
py.test references tests as a fully qualified python
|
``pytest`` references tests using their fully qualified python
|
||||||
module path. **You will otherwise get strange errors**
|
module path. **You will otherwise get strange errors**
|
||||||
during setup of the remote side.
|
during setup of the remote side.
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ You can override the default temporary directory setting like this::
|
||||||
|
|
||||||
py.test --basetemp=mydir
|
py.test --basetemp=mydir
|
||||||
|
|
||||||
When distributing tests on the local machine, ``py.test`` takes care to
|
When distributing tests on the local machine, ``pytest`` takes care to
|
||||||
configure a basetemp directory for the sub processes such that all temporary
|
configure a basetemp directory for the sub processes such that all temporary
|
||||||
data lands below a single per-test run basetemp directory.
|
data lands below a single per-test run basetemp directory.
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,13 @@ Support for unittest.TestCase / Integration of fixtures
|
||||||
|
|
||||||
.. _`unittest.py style`: http://docs.python.org/library/unittest.html
|
.. _`unittest.py style`: http://docs.python.org/library/unittest.html
|
||||||
|
|
||||||
py.test has support for running Python `unittest.py style`_ tests.
|
``pytest`` has support for running Python `unittest.py style`_ tests.
|
||||||
It's meant for leveraging existing unittest-style projects
|
It's meant for leveraging existing unittest-style projects
|
||||||
to use pytest features. Concretely, pytest will automatically
|
to use pytest features. Concretely, pytest will automatically
|
||||||
collect ``unittest.TestCase`` subclasses and their ``test`` methods in
|
collect ``unittest.TestCase`` subclasses and their ``test`` methods in
|
||||||
test files. It will invoke typical setup/teardown methods and
|
test files. It will invoke typical setup/teardown methods and
|
||||||
generally try to make test suites written to run on unittest, to also
|
generally try to make test suites written to run on unittest, to also
|
||||||
run using ``py.test``. We assume here that you are familiar with writing
|
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.
|
||||||
|
|
||||||
|
@ -30,12 +30,12 @@ you can make use of most :ref:`pytest features <features>`, for example
|
||||||
:ref:`more informative tracebacks <tbreportdemo>`, stdout-capturing or
|
:ref:`more informative tracebacks <tbreportdemo>`, stdout-capturing or
|
||||||
distributing tests to multiple CPUs via the ``-nNUM`` option if you
|
distributing tests to multiple CPUs via the ``-nNUM`` option if you
|
||||||
installed the ``pytest-xdist`` plugin. Please refer to
|
installed the ``pytest-xdist`` plugin. Please refer to
|
||||||
the general pytest documentation for many more examples.
|
the general ``pytest`` documentation for many more examples.
|
||||||
|
|
||||||
Mixing pytest fixtures into unittest.TestCase style tests
|
Mixing pytest fixtures into unittest.TestCase style tests
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
|
|
||||||
Running your unittest with ``py.test`` allows you to use its
|
Running your unittest with ``pytest`` allows you to use its
|
||||||
:ref:`fixture mechanism <fixture>` with ``unittest.TestCase`` style
|
:ref:`fixture mechanism <fixture>` with ``unittest.TestCase`` style
|
||||||
tests. Assuming you have at least skimmed the pytest fixture features,
|
tests. Assuming you have at least skimmed the pytest fixture features,
|
||||||
let's jump-start into an example that integrates a pytest ``db_class``
|
let's jump-start into an example that integrates a pytest ``db_class``
|
||||||
|
|
|
@ -72,7 +72,7 @@ Dropping to PDB (Python Debugger) on failures
|
||||||
|
|
||||||
.. _PDB: http://docs.python.org/library/pdb.html
|
.. _PDB: http://docs.python.org/library/pdb.html
|
||||||
|
|
||||||
Python comes with a builtin Python debugger called PDB_. ``py.test``
|
Python comes with a builtin Python debugger called PDB_. ``pytest``
|
||||||
allows one to drop into the PDB prompt via a command line option::
|
allows one to drop into the PDB prompt via a command line option::
|
||||||
|
|
||||||
py.test --pdb
|
py.test --pdb
|
||||||
|
@ -160,7 +160,7 @@ Calling pytest from Python code
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
You can invoke ``py.test`` from Python code directly::
|
You can invoke ``pytest`` from Python code directly::
|
||||||
|
|
||||||
pytest.main()
|
pytest.main()
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
xdist: pytest distributed testing plugin
|
xdist: pytest distributed testing plugin
|
||||||
===============================================================
|
===============================================================
|
||||||
|
|
||||||
The `pytest-xdist`_ plugin extends py.test with some unique
|
The `pytest-xdist`_ plugin extends ``pytest`` with some unique
|
||||||
test execution modes:
|
test execution modes:
|
||||||
|
|
||||||
* Looponfail: run your tests repeatedly in a subprocess. After each
|
* Looponfail: run your tests repeatedly in a subprocess. After each
|
||||||
run, py.test waits until a file in your project changes and then
|
run, ``pytest`` waits until a file in your project changes and then
|
||||||
re-runs the previously failing tests. This is repeated until all
|
re-runs the previously failing tests. This is repeated until all
|
||||||
tests pass. At this point a full run is again performed.
|
tests pass. At this point a full run is again performed.
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ test execution modes:
|
||||||
* Multi-Platform coverage: you can specify different Python interpreters
|
* Multi-Platform coverage: you can specify different Python interpreters
|
||||||
or different platforms and run tests in parallel on all of them.
|
or different platforms and run tests in parallel on all of them.
|
||||||
|
|
||||||
Before running tests remotely, ``py.test`` efficiently "rsyncs" your
|
Before running tests remotely, ``pytest`` efficiently "rsyncs" your
|
||||||
program source code to the remote place. All test results
|
program source code to the remote place. All test results
|
||||||
are reported back and displayed to your local terminal.
|
are reported back and displayed to your local terminal.
|
||||||
You may specify different Python versions and interpreters.
|
You may specify different Python versions and interpreters.
|
||||||
|
@ -86,7 +86,7 @@ you can use the looponfailing mode. Simply add the ``--f`` option::
|
||||||
|
|
||||||
py.test -f
|
py.test -f
|
||||||
|
|
||||||
and py.test will run your tests. Assuming you have failures it will then
|
and ``pytest`` will run your tests. Assuming you have failures it will then
|
||||||
wait for file changes and re-run the failing test set. File changes are detected by looking at ``looponfailingroots`` root directories and all of their contents (recursively). If the default for this value does not work for you you
|
wait for file changes and re-run the failing test set. File changes are detected by looking at ``looponfailingroots`` root directories and all of their contents (recursively). If the default for this value does not work for you you
|
||||||
can change it in your project by setting a configuration option::
|
can change it in your project by setting a configuration option::
|
||||||
|
|
||||||
|
@ -115,11 +115,11 @@ to be sent to the remote side.
|
||||||
|
|
||||||
.. XXX CHECK
|
.. XXX CHECK
|
||||||
|
|
||||||
**NOTE:** For py.test to collect and send tests correctly
|
**NOTE:** For ``pytest`` to collect and send tests correctly
|
||||||
you not only need to make sure all code and tests
|
you not only need to make sure all code and tests
|
||||||
directories are rsynced, but that any test (sub) directory
|
directories are rsynced, but that any test (sub) directory
|
||||||
also has an ``__init__.py`` file because internally
|
also has an ``__init__.py`` file because internally
|
||||||
py.test references tests as a fully qualified python
|
``pytest`` references tests as a fully qualified python
|
||||||
module path. **You will otherwise get strange errors**
|
module path. **You will otherwise get strange errors**
|
||||||
during setup of the remote side.
|
during setup of the remote side.
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -25,7 +25,7 @@ def main():
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='pytest: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.5.2.dev1',
|
version='2.5.2.dev1',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
|
|
|
@ -28,7 +28,7 @@ def test_assert_with_explicit_message():
|
||||||
assert e.msg == 'hello'
|
assert e.msg == 'hello'
|
||||||
|
|
||||||
def test_assert_within_finally():
|
def test_assert_within_finally():
|
||||||
excinfo = py.test.raises(ZeroDivisionError, """
|
excinfo = pytest.raises(ZeroDivisionError, """
|
||||||
try:
|
try:
|
||||||
1/0
|
1/0
|
||||||
finally:
|
finally:
|
||||||
|
@ -79,7 +79,7 @@ def test_is():
|
||||||
assert s.startswith("assert 1 is 2")
|
assert s.startswith("assert 1 is 2")
|
||||||
|
|
||||||
|
|
||||||
@py.test.mark.skipif("sys.version_info < (2,6)")
|
@pytest.mark.skipif("sys.version_info < (2,6)")
|
||||||
def test_attrib():
|
def test_attrib():
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
b = 1
|
b = 1
|
||||||
|
@ -91,7 +91,7 @@ def test_attrib():
|
||||||
s = str(e)
|
s = str(e)
|
||||||
assert s.startswith("assert 1 == 2")
|
assert s.startswith("assert 1 == 2")
|
||||||
|
|
||||||
@py.test.mark.skipif("sys.version_info < (2,6)")
|
@pytest.mark.skipif("sys.version_info < (2,6)")
|
||||||
def test_attrib_inst():
|
def test_attrib_inst():
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
b = 1
|
b = 1
|
||||||
|
@ -168,7 +168,7 @@ def test_assert_with_brokenrepr_arg():
|
||||||
def __repr__(self): 0 / 0
|
def __repr__(self): 0 / 0
|
||||||
e = AssertionError(BrokenRepr())
|
e = AssertionError(BrokenRepr())
|
||||||
if e.msg.find("broken __repr__") == -1:
|
if e.msg.find("broken __repr__") == -1:
|
||||||
py.test.fail("broken __repr__ not handle correctly")
|
pytest.fail("broken __repr__ not handle correctly")
|
||||||
|
|
||||||
def test_multiple_statements_per_line():
|
def test_multiple_statements_per_line():
|
||||||
try:
|
try:
|
||||||
|
@ -244,7 +244,7 @@ class TestView:
|
||||||
assert codelines == ["4 + 5", "getitem('', 'join')",
|
assert codelines == ["4 + 5", "getitem('', 'join')",
|
||||||
"setattr('x', 'y', 3)", "12 - 1"]
|
"setattr('x', 'y', 3)", "12 - 1"]
|
||||||
|
|
||||||
@py.test.mark.skipif("sys.version_info < (2,6)")
|
@pytest.mark.skipif("sys.version_info < (2,6)")
|
||||||
def test_assert_customizable_reprcompare(monkeypatch):
|
def test_assert_customizable_reprcompare(monkeypatch):
|
||||||
monkeypatch.setattr(util, '_reprcompare', lambda *args: 'hello')
|
monkeypatch.setattr(util, '_reprcompare', lambda *args: 'hello')
|
||||||
try:
|
try:
|
||||||
|
@ -323,7 +323,7 @@ def test_assert_raises_in_nonzero_of_object_pytest_issue10():
|
||||||
s = str(e)
|
s = str(e)
|
||||||
assert "<MY42 object> < 0" in s
|
assert "<MY42 object> < 0" in s
|
||||||
|
|
||||||
@py.test.mark.skipif("sys.version_info >= (2,6)")
|
@pytest.mark.skipif("sys.version_info >= (2,6)")
|
||||||
def test_oldinterpret_importation():
|
def test_oldinterpret_importation():
|
||||||
# we had a cyclic import there
|
# we had a cyclic import there
|
||||||
# requires pytest on sys.path
|
# requires pytest on sys.path
|
||||||
|
|
|
@ -280,7 +280,7 @@ def test_options_on_small_file_do_not_blow_up(testdir):
|
||||||
runfiletest(opts + [path])
|
runfiletest(opts + [path])
|
||||||
|
|
||||||
def test_preparse_ordering_with_setuptools(testdir, monkeypatch):
|
def test_preparse_ordering_with_setuptools(testdir, monkeypatch):
|
||||||
pkg_resources = py.test.importorskip("pkg_resources")
|
pkg_resources = pytest.importorskip("pkg_resources")
|
||||||
def my_iter(name):
|
def my_iter(name):
|
||||||
assert name == "pytest11"
|
assert name == "pytest11"
|
||||||
class EntryPoint:
|
class EntryPoint:
|
||||||
|
@ -302,7 +302,7 @@ def test_preparse_ordering_with_setuptools(testdir, monkeypatch):
|
||||||
assert plugin.x == 42
|
assert plugin.x == 42
|
||||||
|
|
||||||
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch):
|
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch):
|
||||||
pkg_resources = py.test.importorskip("pkg_resources")
|
pkg_resources = pytest.importorskip("pkg_resources")
|
||||||
def my_iter(name):
|
def my_iter(name):
|
||||||
assert name == "pytest11"
|
assert name == "pytest11"
|
||||||
class EntryPoint:
|
class EntryPoint:
|
||||||
|
|
|
@ -65,7 +65,7 @@ class TestBootstrapping:
|
||||||
assert l2 == l3
|
assert l2 == l3
|
||||||
|
|
||||||
def test_consider_setuptools_instantiation(self, monkeypatch):
|
def test_consider_setuptools_instantiation(self, monkeypatch):
|
||||||
pkg_resources = py.test.importorskip("pkg_resources")
|
pkg_resources = pytest.importorskip("pkg_resources")
|
||||||
def my_iter(name):
|
def my_iter(name):
|
||||||
assert name == "pytest11"
|
assert name == "pytest11"
|
||||||
class EntryPoint:
|
class EntryPoint:
|
||||||
|
@ -334,11 +334,11 @@ class TestPytestPluginInteractions:
|
||||||
return {'hello': 'world'}
|
return {'hello': 'world'}
|
||||||
""")
|
""")
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
from py.test import hello
|
from pytest import hello
|
||||||
import py
|
import pytest
|
||||||
def test_hello():
|
def test_hello():
|
||||||
assert hello == "world"
|
assert hello == "world"
|
||||||
assert 'hello' in py.test.__all__
|
assert 'hello' in pytest.__all__
|
||||||
""")
|
""")
|
||||||
reprec = testdir.inline_run(p)
|
reprec = testdir.inline_run(p)
|
||||||
reprec.assertoutcome(passed=1)
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
|
@ -6,7 +6,7 @@ def test_version(testdir, pytestconfig):
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
#p = py.path.local(py.__file__).dirpath()
|
#p = py.path.local(py.__file__).dirpath()
|
||||||
result.stderr.fnmatch_lines([
|
result.stderr.fnmatch_lines([
|
||||||
'*py.test*%s*imported from*' % (pytest.__version__, )
|
'*pytest*%s*imported from*' % (pytest.__version__, )
|
||||||
])
|
])
|
||||||
if pytestconfig.pluginmanager._plugin_distinfo:
|
if pytestconfig.pluginmanager._plugin_distinfo:
|
||||||
result.stderr.fnmatch_lines([
|
result.stderr.fnmatch_lines([
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import py, pytest
|
import py, pytest
|
||||||
|
|
||||||
def setup_module(mod):
|
def setup_module(mod):
|
||||||
mod.nose = py.test.importorskip("nose")
|
mod.nose = pytest.importorskip("nose")
|
||||||
|
|
||||||
def test_nose_setup(testdir):
|
def test_nose_setup(testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
|
@ -112,7 +112,7 @@ def test_nose_setup_func_failure_2(testdir):
|
||||||
reprec.assertoutcome(passed=1)
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
||||||
def test_nose_setup_partial(testdir):
|
def test_nose_setup_partial(testdir):
|
||||||
py.test.importorskip("functools")
|
pytest.importorskip("functools")
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ def test_parseconfig(testdir):
|
||||||
config1 = testdir.parseconfig()
|
config1 = testdir.parseconfig()
|
||||||
config2 = testdir.parseconfig()
|
config2 = testdir.parseconfig()
|
||||||
assert config2 != config1
|
assert config2 != config1
|
||||||
assert config1 != py.test.config
|
assert config1 != pytest.config
|
||||||
|
|
||||||
def test_testdir_runs_with_plugin(testdir):
|
def test_testdir_runs_with_plugin(testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
|
|
@ -37,7 +37,7 @@ def test_recwarn_functional(testdir):
|
||||||
assert tuple(res) == (2, 0, 0), res
|
assert tuple(res) == (2, 0, 0), res
|
||||||
|
|
||||||
#
|
#
|
||||||
# ============ test py.test.deprecated_call() ==============
|
# ============ test pytest.deprecated_call() ==============
|
||||||
#
|
#
|
||||||
|
|
||||||
def dep(i):
|
def dep(i):
|
||||||
|
@ -53,14 +53,14 @@ def dep_explicit(i):
|
||||||
|
|
||||||
def test_deprecated_call_raises():
|
def test_deprecated_call_raises():
|
||||||
excinfo = pytest.raises(AssertionError,
|
excinfo = pytest.raises(AssertionError,
|
||||||
"py.test.deprecated_call(dep, 3)")
|
"pytest.deprecated_call(dep, 3)")
|
||||||
assert str(excinfo).find("did not produce") != -1
|
assert str(excinfo).find("did not produce") != -1
|
||||||
|
|
||||||
def test_deprecated_call():
|
def test_deprecated_call():
|
||||||
py.test.deprecated_call(dep, 0)
|
pytest.deprecated_call(dep, 0)
|
||||||
|
|
||||||
def test_deprecated_call_ret():
|
def test_deprecated_call_ret():
|
||||||
ret = py.test.deprecated_call(dep, 0)
|
ret = pytest.deprecated_call(dep, 0)
|
||||||
assert ret == 42
|
assert ret == 42
|
||||||
|
|
||||||
def test_deprecated_call_preserves():
|
def test_deprecated_call_preserves():
|
||||||
|
@ -73,9 +73,9 @@ def test_deprecated_call_preserves():
|
||||||
|
|
||||||
def test_deprecated_explicit_call_raises():
|
def test_deprecated_explicit_call_raises():
|
||||||
pytest.raises(AssertionError,
|
pytest.raises(AssertionError,
|
||||||
"py.test.deprecated_call(dep_explicit, 3)")
|
"pytest.deprecated_call(dep_explicit, 3)")
|
||||||
|
|
||||||
def test_deprecated_explicit_call():
|
def test_deprecated_explicit_call():
|
||||||
py.test.deprecated_call(dep_explicit, 0)
|
pytest.deprecated_call(dep_explicit, 0)
|
||||||
py.test.deprecated_call(dep_explicit, 0)
|
pytest.deprecated_call(dep_explicit, 0)
|
||||||
|
|
||||||
|
|
|
@ -268,7 +268,7 @@ class BaseFunctionalTests:
|
||||||
raise SystemExit(42)
|
raise SystemExit(42)
|
||||||
""")
|
""")
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
py.test.fail("runner did not catch SystemExit")
|
pytest.fail("runner did not catch SystemExit")
|
||||||
rep = reports[1]
|
rep = reports[1]
|
||||||
assert rep.failed
|
assert rep.failed
|
||||||
assert rep.when == "call"
|
assert rep.when == "call"
|
||||||
|
@ -280,10 +280,10 @@ class BaseFunctionalTests:
|
||||||
def test_func():
|
def test_func():
|
||||||
raise pytest.exit.Exception()
|
raise pytest.exit.Exception()
|
||||||
""")
|
""")
|
||||||
except py.test.exit.Exception:
|
except pytest.exit.Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
py.test.fail("did not raise")
|
pytest.fail("did not raise")
|
||||||
|
|
||||||
class TestExecutionNonForked(BaseFunctionalTests):
|
class TestExecutionNonForked(BaseFunctionalTests):
|
||||||
def getrunner(self):
|
def getrunner(self):
|
||||||
|
@ -300,14 +300,14 @@ class TestExecutionNonForked(BaseFunctionalTests):
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
py.test.fail("did not raise")
|
pytest.fail("did not raise")
|
||||||
|
|
||||||
class TestExecutionForked(BaseFunctionalTests):
|
class TestExecutionForked(BaseFunctionalTests):
|
||||||
pytestmark = pytest.mark.skipif("not hasattr(os, 'fork')")
|
pytestmark = pytest.mark.skipif("not hasattr(os, 'fork')")
|
||||||
|
|
||||||
def getrunner(self):
|
def getrunner(self):
|
||||||
# XXX re-arrange this test to live in pytest-xdist
|
# XXX re-arrange this test to live in pytest-xdist
|
||||||
xplugin = py.test.importorskip("xdist.plugin")
|
xplugin = pytest.importorskip("xdist.plugin")
|
||||||
return xplugin.forked_run_report
|
return xplugin.forked_run_report
|
||||||
|
|
||||||
def test_suicide(self, testdir):
|
def test_suicide(self, testdir):
|
||||||
|
@ -417,15 +417,15 @@ def test_outcomeexception_exceptionattributes():
|
||||||
|
|
||||||
def test_pytest_exit():
|
def test_pytest_exit():
|
||||||
try:
|
try:
|
||||||
py.test.exit("hello")
|
pytest.exit("hello")
|
||||||
except py.test.exit.Exception:
|
except pytest.exit.Exception:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
assert excinfo.errisinstance(KeyboardInterrupt)
|
assert excinfo.errisinstance(KeyboardInterrupt)
|
||||||
|
|
||||||
def test_pytest_fail():
|
def test_pytest_fail():
|
||||||
try:
|
try:
|
||||||
py.test.fail("hello")
|
pytest.fail("hello")
|
||||||
except py.test.fail.Exception:
|
except pytest.fail.Exception:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
s = excinfo.exconly(tryshort=True)
|
s = excinfo.exconly(tryshort=True)
|
||||||
assert s.startswith("Failed")
|
assert s.startswith("Failed")
|
||||||
|
@ -454,45 +454,45 @@ def test_exception_printing_skip():
|
||||||
assert s.startswith("Skipped")
|
assert s.startswith("Skipped")
|
||||||
|
|
||||||
def test_importorskip():
|
def test_importorskip():
|
||||||
importorskip = py.test.importorskip
|
importorskip = pytest.importorskip
|
||||||
def f():
|
def f():
|
||||||
importorskip("asdlkj")
|
importorskip("asdlkj")
|
||||||
try:
|
try:
|
||||||
sys = importorskip("sys") # noqa
|
sys = importorskip("sys") # noqa
|
||||||
assert sys == py.std.sys
|
assert sys == py.std.sys
|
||||||
#path = py.test.importorskip("os.path")
|
#path = pytest.importorskip("os.path")
|
||||||
#assert path == py.std.os.path
|
#assert path == py.std.os.path
|
||||||
excinfo = pytest.raises(pytest.skip.Exception, f)
|
excinfo = pytest.raises(pytest.skip.Exception, f)
|
||||||
path = py.path.local(excinfo.getrepr().reprcrash.path)
|
path = py.path.local(excinfo.getrepr().reprcrash.path)
|
||||||
# check that importorskip reports the actual call
|
# check that importorskip reports the actual call
|
||||||
# in this test the test_runner.py file
|
# in this test the test_runner.py file
|
||||||
assert path.purebasename == "test_runner"
|
assert path.purebasename == "test_runner"
|
||||||
pytest.raises(SyntaxError, "py.test.importorskip('x y z')")
|
pytest.raises(SyntaxError, "pytest.importorskip('x y z')")
|
||||||
pytest.raises(SyntaxError, "py.test.importorskip('x=y')")
|
pytest.raises(SyntaxError, "pytest.importorskip('x=y')")
|
||||||
mod = py.std.types.ModuleType("hello123")
|
mod = py.std.types.ModuleType("hello123")
|
||||||
mod.__version__ = "1.3"
|
mod.__version__ = "1.3"
|
||||||
sys.modules["hello123"] = mod
|
sys.modules["hello123"] = mod
|
||||||
pytest.raises(pytest.skip.Exception, """
|
pytest.raises(pytest.skip.Exception, """
|
||||||
py.test.importorskip("hello123", minversion="1.3.1")
|
pytest.importorskip("hello123", minversion="1.3.1")
|
||||||
""")
|
""")
|
||||||
mod2 = pytest.importorskip("hello123", minversion="1.3")
|
mod2 = pytest.importorskip("hello123", minversion="1.3")
|
||||||
assert mod2 == mod
|
assert mod2 == mod
|
||||||
except pytest.skip.Exception:
|
except pytest.skip.Exception:
|
||||||
print(py.code.ExceptionInfo())
|
print(py.code.ExceptionInfo())
|
||||||
py.test.fail("spurious skip")
|
pytest.fail("spurious skip")
|
||||||
|
|
||||||
def test_importorskip_imports_last_module_part():
|
def test_importorskip_imports_last_module_part():
|
||||||
ospath = py.test.importorskip("os.path")
|
ospath = pytest.importorskip("os.path")
|
||||||
assert os.path == ospath
|
assert os.path == ospath
|
||||||
|
|
||||||
|
|
||||||
def test_pytest_cmdline_main(testdir):
|
def test_pytest_cmdline_main(testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
import py
|
import pytest
|
||||||
def test_hello():
|
def test_hello():
|
||||||
assert 1
|
assert 1
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
py.test.cmdline.main([__file__])
|
pytest.cmdline.main([__file__])
|
||||||
""")
|
""")
|
||||||
import subprocess
|
import subprocess
|
||||||
popen = subprocess.Popen([sys.executable, str(p)], stdout=subprocess.PIPE)
|
popen = subprocess.Popen([sys.executable, str(p)], stdout=subprocess.PIPE)
|
||||||
|
|
|
@ -54,7 +54,7 @@ class SessionTests:
|
||||||
out = failed[0].longrepr.reprcrash.message
|
out = failed[0].longrepr.reprcrash.message
|
||||||
if not out.find("DID NOT RAISE") != -1:
|
if not out.find("DID NOT RAISE") != -1:
|
||||||
print(out)
|
print(out)
|
||||||
py.test.fail("incorrect raises() output")
|
pytest.fail("incorrect raises() output")
|
||||||
|
|
||||||
def test_generator_yields_None(self, testdir):
|
def test_generator_yields_None(self, testdir):
|
||||||
reprec = testdir.inline_runsource("""
|
reprec = testdir.inline_runsource("""
|
||||||
|
@ -127,7 +127,7 @@ class SessionTests:
|
||||||
try:
|
try:
|
||||||
reprec = testdir.inline_run(testdir.tmpdir)
|
reprec = testdir.inline_run(testdir.tmpdir)
|
||||||
except pytest.skip.Exception:
|
except pytest.skip.Exception:
|
||||||
py.test.fail("wrong skipped caught")
|
pytest.fail("wrong skipped caught")
|
||||||
reports = reprec.getreports("pytest_collectreport")
|
reports = reprec.getreports("pytest_collectreport")
|
||||||
assert len(reports) == 1
|
assert len(reports) == 1
|
||||||
assert reports[0].skipped
|
assert reports[0].skipped
|
||||||
|
|
|
@ -27,9 +27,9 @@ def test_funcarg(testdir):
|
||||||
assert bn == "qwe__abc"
|
assert bn == "qwe__abc"
|
||||||
|
|
||||||
def test_ensuretemp(recwarn):
|
def test_ensuretemp(recwarn):
|
||||||
#py.test.deprecated_call(py.test.ensuretemp, 'hello')
|
#pytest.deprecated_call(pytest.ensuretemp, 'hello')
|
||||||
d1 = py.test.ensuretemp('hello')
|
d1 = pytest.ensuretemp('hello')
|
||||||
d2 = py.test.ensuretemp('hello')
|
d2 = pytest.ensuretemp('hello')
|
||||||
assert d1 == d2
|
assert d1 == d2
|
||||||
assert d1.check(dir=1)
|
assert d1.check(dir=1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue