Compare commits
81 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b91bc88de | ||
|
|
6690b8a444 | ||
|
|
7093d8f65e | ||
|
|
966391c77e | ||
|
|
9c8847a0cb | ||
|
|
58aaabbb10 | ||
|
|
2802135741 | ||
|
|
bf77daa2ee | ||
|
|
9933635cf7 | ||
|
|
ac5c5cc1ef | ||
|
|
810320f591 | ||
|
|
25d2acbdb2 | ||
|
|
52c134aed3 | ||
|
|
70cdfaf661 | ||
|
|
abfd9774ef | ||
|
|
e57cc55719 | ||
|
|
696c702da7 | ||
|
|
bee2c864d8 | ||
|
|
e27a0d69aa | ||
|
|
15222ceca2 | ||
|
|
3c1ca03b9c | ||
|
|
25ed4edbc7 | ||
|
|
1e93089165 | ||
|
|
b2a8e06e4f | ||
|
|
09349c344e | ||
|
|
6cf515b164 | ||
|
|
c52f87ede3 | ||
|
|
549f5c1a47 | ||
|
|
3f8ff7f090 | ||
|
|
ad36407747 | ||
|
|
10d43bd3bf | ||
|
|
1fc185b640 | ||
|
|
181bd60bf9 | ||
|
|
3288c9a110 | ||
|
|
5e00549ecc | ||
|
|
b770a32dc8 | ||
|
|
f9157b1b6b | ||
|
|
f4e811afc0 | ||
|
|
59cdef92be | ||
|
|
709b8b65a4 | ||
|
|
0824076e11 | ||
|
|
67161ee9f8 | ||
|
|
1c891d7d97 | ||
|
|
12b1bff6c5 | ||
|
|
657976e98a | ||
|
|
a993add783 | ||
|
|
539523cfee | ||
|
|
f18780ed8a | ||
|
|
806d47b4d4 | ||
|
|
bfc9f61482 | ||
|
|
2a99d82c3b | ||
|
|
9b2753b302 | ||
|
|
e9bfccdf2d | ||
|
|
7b5d26c1a8 | ||
|
|
362b1b3c4f | ||
|
|
5c0c1977e3 | ||
|
|
39331856ed | ||
|
|
dc9154e8ff | ||
|
|
021fba4e84 | ||
|
|
fd84c886ee | ||
|
|
e6020781f6 | ||
|
|
acd3c4fbc4 | ||
|
|
c847b83d56 | ||
|
|
45d2962e97 | ||
|
|
8b322afcdb | ||
|
|
523bfa6151 | ||
|
|
cc0f2473eb | ||
|
|
76c55b31c6 | ||
|
|
a0101f024e | ||
|
|
d5f4496bdf | ||
|
|
37353a854e | ||
|
|
12e60956de | ||
|
|
15cdf137d5 | ||
|
|
ad52f714a9 | ||
|
|
8969bd43c9 | ||
|
|
7703dc921c | ||
|
|
1deac2e210 | ||
|
|
02da156351 | ||
|
|
84061233ef | ||
|
|
0a15edd573 | ||
|
|
51ebad76f2 |
22
.travis.yml
22
.travis.yml
@@ -1,9 +1,10 @@
|
||||
sudo: false
|
||||
language: python
|
||||
python:
|
||||
- '3.5'
|
||||
- '3.6'
|
||||
# command to install dependencies
|
||||
install: "pip install -U tox"
|
||||
install:
|
||||
- pip install --upgrade --pre tox
|
||||
# # command to run tests
|
||||
env:
|
||||
matrix:
|
||||
@@ -13,18 +14,17 @@ env:
|
||||
- TOXENV=linting
|
||||
- TOXENV=py27
|
||||
- TOXENV=py34
|
||||
- TOXENV=py35
|
||||
- TOXENV=py36
|
||||
- TOXENV=py27-pexpect
|
||||
- TOXENV=py27-xdist
|
||||
- TOXENV=py27-trial
|
||||
- TOXENV=py27-numpy
|
||||
- TOXENV=py35-pexpect
|
||||
- TOXENV=py35-xdist
|
||||
- TOXENV=py35-trial
|
||||
- TOXENV=py35-numpy
|
||||
- TOXENV=py36-pexpect
|
||||
- TOXENV=py36-xdist
|
||||
- TOXENV=py36-trial
|
||||
- TOXENV=py36-numpy
|
||||
- TOXENV=py27-nobyte
|
||||
- TOXENV=doctesting
|
||||
- TOXENV=freeze
|
||||
- TOXENV=docs
|
||||
|
||||
matrix:
|
||||
@@ -35,8 +35,10 @@ matrix:
|
||||
python: '3.3'
|
||||
- env: TOXENV=pypy
|
||||
python: 'pypy-5.4'
|
||||
- env: TOXENV=py36
|
||||
python: '3.6'
|
||||
- env: TOXENV=py35
|
||||
python: '3.5'
|
||||
- env: TOXENV=py35-freeze
|
||||
python: '3.5'
|
||||
- env: TOXENV=py37
|
||||
python: 'nightly'
|
||||
allow_failures:
|
||||
|
||||
2
AUTHORS
2
AUTHORS
@@ -155,6 +155,7 @@ Samuele Pedroni
|
||||
Segev Finer
|
||||
Simon Gomizelj
|
||||
Skylar Downes
|
||||
Srinivas Reddy Thatiparthy
|
||||
Stefan Farmbauer
|
||||
Stefan Zimmermann
|
||||
Stefano Taschini
|
||||
@@ -172,5 +173,6 @@ Vidar T. Fauske
|
||||
Vitaly Lashmanov
|
||||
Vlad Dragos
|
||||
Wouter van Ackooy
|
||||
Xuan Luong
|
||||
Xuecong Liao
|
||||
Zoltán Máté
|
||||
|
||||
119
CHANGELOG.rst
119
CHANGELOG.rst
@@ -8,6 +8,123 @@
|
||||
|
||||
.. towncrier release notes start
|
||||
|
||||
Pytest 3.2.3 (2017-10-03)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- Fix crash in tab completion when no prefix is given. (`#2748
|
||||
<https://github.com/pytest-dev/pytest/issues/2748>`_)
|
||||
|
||||
- The equality checking function (``__eq__``) of ``MarkDecorator`` returns
|
||||
``False`` if one object is not an instance of ``MarkDecorator``. (`#2758
|
||||
<https://github.com/pytest-dev/pytest/issues/2758>`_)
|
||||
|
||||
- When running ``pytest --fixtures-per-test``: don't crash if an item has no
|
||||
_fixtureinfo attribute (e.g. doctests) (`#2788
|
||||
<https://github.com/pytest-dev/pytest/issues/2788>`_)
|
||||
|
||||
|
||||
Improved Documentation
|
||||
----------------------
|
||||
|
||||
- In help text of ``-k`` option, add example of using ``not`` to not select
|
||||
certain tests whose names match the provided expression. (`#1442
|
||||
<https://github.com/pytest-dev/pytest/issues/1442>`_)
|
||||
|
||||
- Add note in ``parametrize.rst`` about calling ``metafunc.parametrize``
|
||||
multiple times. (`#1548 <https://github.com/pytest-dev/pytest/issues/1548>`_)
|
||||
|
||||
|
||||
Trivial/Internal Changes
|
||||
------------------------
|
||||
|
||||
- Set ``xfail_strict=True`` in pytest's own test suite to catch expected
|
||||
failures as soon as they start to pass. (`#2722
|
||||
<https://github.com/pytest-dev/pytest/issues/2722>`_)
|
||||
|
||||
- Fix typo in example of passing a callable to markers (in example/markers.rst)
|
||||
(`#2765 <https://github.com/pytest-dev/pytest/issues/2765>`_)
|
||||
|
||||
|
||||
Pytest 3.2.2 (2017-09-06)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- Calling the deprecated `request.getfuncargvalue()` now shows the source of
|
||||
the call. (`#2681 <https://github.com/pytest-dev/pytest/issues/2681>`_)
|
||||
|
||||
- Allow tests declared as ``@staticmethod`` to use fixtures. (`#2699
|
||||
<https://github.com/pytest-dev/pytest/issues/2699>`_)
|
||||
|
||||
- Fixed edge-case during collection: attributes which raised ``pytest.fail``
|
||||
when accessed would abort the entire collection. (`#2707
|
||||
<https://github.com/pytest-dev/pytest/issues/2707>`_)
|
||||
|
||||
- Fix ``ReprFuncArgs`` with mixed unicode and UTF-8 args. (`#2731
|
||||
<https://github.com/pytest-dev/pytest/issues/2731>`_)
|
||||
|
||||
|
||||
Improved Documentation
|
||||
----------------------
|
||||
|
||||
- In examples on working with custom markers, add examples demonstrating the
|
||||
usage of ``pytest.mark.MARKER_NAME.with_args`` in comparison with
|
||||
``pytest.mark.MARKER_NAME.__call__`` (`#2604
|
||||
<https://github.com/pytest-dev/pytest/issues/2604>`_)
|
||||
|
||||
- In one of the simple examples, use `pytest_collection_modifyitems()` to skip
|
||||
tests based on a command-line option, allowing its sharing while preventing a
|
||||
user error when acessing `pytest.config` before the argument parsing. (`#2653
|
||||
<https://github.com/pytest-dev/pytest/issues/2653>`_)
|
||||
|
||||
|
||||
Trivial/Internal Changes
|
||||
------------------------
|
||||
|
||||
- Fixed minor error in 'Good Practices/Manual Integration' code snippet.
|
||||
(`#2691 <https://github.com/pytest-dev/pytest/issues/2691>`_)
|
||||
|
||||
- Fixed typo in goodpractices.rst. (`#2721
|
||||
<https://github.com/pytest-dev/pytest/issues/2721>`_)
|
||||
|
||||
- Improve user guidance regarding ``--resultlog`` deprecation. (`#2739
|
||||
<https://github.com/pytest-dev/pytest/issues/2739>`_)
|
||||
|
||||
|
||||
Pytest 3.2.1 (2017-08-08)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- Fixed small terminal glitch when collecting a single test item. (`#2579
|
||||
<https://github.com/pytest-dev/pytest/issues/2579>`_)
|
||||
|
||||
- Correctly consider ``/`` as the file separator to automatically mark plugin
|
||||
files for rewrite on Windows. (`#2591 <https://github.com/pytest-
|
||||
dev/pytest/issues/2591>`_)
|
||||
|
||||
- Properly escape test names when setting ``PYTEST_CURRENT_TEST`` environment
|
||||
variable. (`#2644 <https://github.com/pytest-dev/pytest/issues/2644>`_)
|
||||
|
||||
- Fix error on Windows and Python 3.6+ when ``sys.stdout`` has been replaced
|
||||
with a stream-like object which does not implement the full ``io`` module
|
||||
buffer protocol. In particular this affects ``pytest-xdist`` users on the
|
||||
aforementioned platform. (`#2666 <https://github.com/pytest-
|
||||
dev/pytest/issues/2666>`_)
|
||||
|
||||
|
||||
Improved Documentation
|
||||
----------------------
|
||||
|
||||
- Explicitly document which pytest features work with ``unittest``. (`#2626
|
||||
<https://github.com/pytest-dev/pytest/issues/2626>`_)
|
||||
|
||||
|
||||
Pytest 3.2.0 (2017-07-30)
|
||||
=========================
|
||||
|
||||
@@ -113,7 +230,7 @@ Bug Fixes
|
||||
- capture: ensure that EncodedFile.name is a string. (`#2555
|
||||
<https://github.com/pytest-dev/pytest/issues/2555>`_)
|
||||
|
||||
- The options ```--fixtures`` and ```--fixtures-per-test`` will now keep
|
||||
- The options ``--fixtures`` and ``--fixtures-per-test`` will now keep
|
||||
indentation within docstrings. (`#2574 <https://github.com/pytest-
|
||||
dev/pytest/issues/2574>`_)
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ the following:
|
||||
- PyPI presence with a ``setup.py`` that contains a license, ``pytest-``
|
||||
prefixed name, version number, authors, short and long description.
|
||||
|
||||
- a ``tox.ini`` for running tests using `tox <http://tox.testrun.org>`_.
|
||||
- a ``tox.ini`` for running tests using `tox <https://tox.readthedocs.io>`_.
|
||||
|
||||
- a ``README.txt`` describing how to use the plugin and on which
|
||||
platforms it runs.
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
How to release pytest
|
||||
--------------------------------------------
|
||||
Release Procedure
|
||||
-----------------
|
||||
|
||||
Our current policy for releasing is to aim for a bugfix every few weeks and a minor release every 2-3 months. The idea
|
||||
is to get fixes and new features out instead of trying to cram a ton of features into a release and by consequence
|
||||
taking a lot of time to make a new one.
|
||||
|
||||
.. important::
|
||||
|
||||
@@ -21,7 +25,7 @@ How to release pytest
|
||||
#. Generate docs, changelog, announcements and upload a package to
|
||||
your ``devpi`` staging server::
|
||||
|
||||
invoke generate.pre_release <VERSION> <DEVPI USER> --password <DEVPI PASSWORD>
|
||||
invoke generate.pre-release <VERSION> <DEVPI USER> --password <DEVPI PASSWORD>
|
||||
|
||||
If ``--password`` is not given, it is assumed the user is already logged in ``devpi``.
|
||||
If you don't have an account, please ask for one.
|
||||
@@ -49,12 +53,12 @@ How to release pytest
|
||||
|
||||
#. Publish to PyPI::
|
||||
|
||||
invoke generate.publish_release <VERSION> <DEVPI USER> <PYPI_NAME>
|
||||
invoke generate.publish-release <VERSION> <DEVPI USER> <PYPI_NAME>
|
||||
|
||||
where PYPI_NAME is the name of pypi.python.org as configured in your ``~/.pypirc``
|
||||
file `for devpi <http://doc.devpi.net/latest/quickstart-releaseprocess.html?highlight=pypirc#devpi-push-releasing-to-an-external-index>`_.
|
||||
|
||||
#. After a minor/major release, merge ``features`` into ``master`` and push (or open a PR).
|
||||
#. After a minor/major release, merge ``release-X.Y.Z`` into ``master`` and push (or open a PR).
|
||||
|
||||
.. _devpi-cloud-test: https://github.com/obestwalter/devpi-cloud-test
|
||||
.. _AppVeyor: https://www.appveyor.com/
|
||||
|
||||
@@ -78,7 +78,7 @@ Features
|
||||
|
||||
- Python2.6+, Python3.3+, PyPy-2.3, Jython-2.5 (untested);
|
||||
|
||||
- Rich plugin architecture, with over 150+ `external plugins <http://docs.pytest.org/en/latest/plugins.html#installing-external-plugins-searching>`_ and thriving community;
|
||||
- Rich plugin architecture, with over 315+ `external plugins <http://plugincompat.herokuapp.com>`_ and thriving community;
|
||||
|
||||
|
||||
Documentation
|
||||
|
||||
@@ -78,7 +78,8 @@ class FastFilesCompleter:
|
||||
completion = []
|
||||
globbed = []
|
||||
if '*' not in prefix and '?' not in prefix:
|
||||
if prefix[-1] == os.path.sep: # we are on unix, otherwise no bash
|
||||
# we are on unix, otherwise no bash
|
||||
if not prefix or prefix[-1] == os.path.sep:
|
||||
globbed.extend(glob(prefix + '.*'))
|
||||
prefix += '*'
|
||||
globbed.extend(glob(prefix))
|
||||
@@ -98,7 +99,7 @@ if os.environ.get('_ARGCOMPLETE'):
|
||||
filescompleter = FastFilesCompleter()
|
||||
|
||||
def try_argcomplete(parser):
|
||||
argcomplete.autocomplete(parser)
|
||||
argcomplete.autocomplete(parser, always_complete_options=False)
|
||||
else:
|
||||
def try_argcomplete(parser):
|
||||
pass
|
||||
|
||||
@@ -863,7 +863,7 @@ class ReprFuncArgs(TerminalRepr):
|
||||
if self.args:
|
||||
linesofar = ""
|
||||
for name, value in self.args:
|
||||
ns = "%s = %s" % (name, value)
|
||||
ns = "%s = %s" % (safe_str(name), safe_str(value))
|
||||
if len(ns) + len(linesofar) + 2 > tw.fullwidth:
|
||||
if linesofar:
|
||||
tw.line(linesofar)
|
||||
|
||||
@@ -36,7 +36,7 @@ def pytest_addoption(parser):
|
||||
def pytest_load_initial_conftests(early_config, parser, args):
|
||||
ns = early_config.known_args_namespace
|
||||
if ns.capture == "fd":
|
||||
_py36_windowsconsoleio_workaround()
|
||||
_py36_windowsconsoleio_workaround(sys.stdout)
|
||||
_colorama_workaround()
|
||||
_readline_workaround()
|
||||
pluginmanager = early_config.pluginmanager
|
||||
@@ -524,7 +524,7 @@ def _readline_workaround():
|
||||
pass
|
||||
|
||||
|
||||
def _py36_windowsconsoleio_workaround():
|
||||
def _py36_windowsconsoleio_workaround(stream):
|
||||
"""
|
||||
Python 3.6 implemented unicode console handling for Windows. This works
|
||||
by reading/writing to the raw console handle using
|
||||
@@ -541,13 +541,20 @@ def _py36_windowsconsoleio_workaround():
|
||||
also means a different handle by replicating the logic in
|
||||
"Py_lifecycle.c:initstdio/create_stdio".
|
||||
|
||||
:param stream: in practice ``sys.stdout`` or ``sys.stderr``, but given
|
||||
here as parameter for unittesting purposes.
|
||||
|
||||
See https://github.com/pytest-dev/py/issues/103
|
||||
"""
|
||||
if not sys.platform.startswith('win32') or sys.version_info[:2] < (3, 6):
|
||||
return
|
||||
|
||||
buffered = hasattr(sys.stdout.buffer, 'raw')
|
||||
raw_stdout = sys.stdout.buffer.raw if buffered else sys.stdout.buffer
|
||||
# bail out if ``stream`` doesn't seem like a proper ``io`` stream (#2666)
|
||||
if not hasattr(stream, 'buffer'):
|
||||
return
|
||||
|
||||
buffered = hasattr(stream.buffer, 'raw')
|
||||
raw_stdout = stream.buffer.raw if buffered else stream.buffer
|
||||
|
||||
if not isinstance(raw_stdout, io._WindowsConsoleIO):
|
||||
return
|
||||
|
||||
@@ -11,6 +11,7 @@ import functools
|
||||
import py
|
||||
|
||||
import _pytest
|
||||
from _pytest.outcomes import TEST_OUTCOME
|
||||
|
||||
|
||||
try:
|
||||
@@ -82,7 +83,15 @@ def num_mock_patch_args(function):
|
||||
return len(patchings)
|
||||
|
||||
|
||||
def getfuncargnames(function, startindex=None):
|
||||
def getfuncargnames(function, startindex=None, cls=None):
|
||||
"""
|
||||
@RonnyPfannschmidt: This function should be refactored when we revisit fixtures. The
|
||||
fixture mechanism should ask the node for the fixture names, and not try to obtain
|
||||
directly from the function object well after collection has occurred.
|
||||
"""
|
||||
if startindex is None and cls is not None:
|
||||
is_staticmethod = isinstance(cls.__dict__.get(function.__name__, None), staticmethod)
|
||||
startindex = 0 if is_staticmethod else 1
|
||||
# XXX merge with main.py's varnames
|
||||
# assert not isclass(function)
|
||||
realfunction = function
|
||||
@@ -221,14 +230,16 @@ def getimfunc(func):
|
||||
|
||||
|
||||
def safe_getattr(object, name, default):
|
||||
""" Like getattr but return default upon any Exception.
|
||||
""" Like getattr but return default upon any Exception or any OutcomeException.
|
||||
|
||||
Attribute access can potentially fail for 'evil' Python objects.
|
||||
See issue #214.
|
||||
It catches OutcomeException because of #2490 (issue #580), new outcomes are derived from BaseException
|
||||
instead of Exception (for more details check #2707)
|
||||
"""
|
||||
try:
|
||||
return getattr(object, name, default)
|
||||
except Exception:
|
||||
except TEST_OUTCOME:
|
||||
return default
|
||||
|
||||
|
||||
|
||||
@@ -881,6 +881,18 @@ notset = Notset()
|
||||
FILE_OR_DIR = 'file_or_dir'
|
||||
|
||||
|
||||
def _iter_rewritable_modules(package_files):
|
||||
for fn in package_files:
|
||||
is_simple_module = '/' not in fn and fn.endswith('.py')
|
||||
is_package = fn.count('/') == 1 and fn.endswith('__init__.py')
|
||||
if is_simple_module:
|
||||
module_name, _ = os.path.splitext(fn)
|
||||
yield module_name
|
||||
elif is_package:
|
||||
package_name = os.path.dirname(fn)
|
||||
yield package_name
|
||||
|
||||
|
||||
class Config(object):
|
||||
""" access to configuration values, pluginmanager and plugin hooks. """
|
||||
|
||||
@@ -1041,15 +1053,8 @@ class Config(object):
|
||||
for entry in entrypoint.dist._get_metadata(metadata)
|
||||
)
|
||||
|
||||
for fn in package_files:
|
||||
is_simple_module = os.sep not in fn and fn.endswith('.py')
|
||||
is_package = fn.count(os.sep) == 1 and fn.endswith('__init__.py')
|
||||
if is_simple_module:
|
||||
module_name, ext = os.path.splitext(fn)
|
||||
hook.mark_rewrite(module_name)
|
||||
elif is_package:
|
||||
package_name = os.path.dirname(fn)
|
||||
hook.mark_rewrite(package_name)
|
||||
for name in _iter_rewritable_modules(package_files):
|
||||
hook.mark_rewrite(name)
|
||||
|
||||
def _warn_about_missing_assertion(self, mode):
|
||||
try:
|
||||
@@ -1351,7 +1356,7 @@ def determine_setup(inifile, args, warnfunc=None):
|
||||
rootdir, inifile, inicfg = getcfg(dirs, warnfunc=warnfunc)
|
||||
if rootdir is None:
|
||||
rootdir = get_common_ancestor([py.path.local(), ancestor])
|
||||
is_fs_root = os.path.splitdrive(str(rootdir))[1] == os.sep
|
||||
is_fs_root = os.path.splitdrive(str(rootdir))[1] == '/'
|
||||
if is_fs_root:
|
||||
rootdir = ancestor
|
||||
return rootdir, inifile, inicfg or {}
|
||||
|
||||
@@ -26,7 +26,10 @@ SETUP_CFG_PYTEST = '[pytest] section in setup.cfg files is deprecated, use [tool
|
||||
|
||||
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
|
||||
|
||||
RESULT_LOG = '--result-log is deprecated and scheduled for removal in pytest 4.0'
|
||||
RESULT_LOG = (
|
||||
'--result-log is deprecated and scheduled for removal in pytest 4.0.\n'
|
||||
'See https://docs.pytest.org/en/latest/usage.html#creating-resultlog-format-files for more information.'
|
||||
)
|
||||
|
||||
MARK_INFO_ATTRIBUTE = RemovedInPytest4Warning(
|
||||
"MarkInfo objects are deprecated as they contain the merged marks"
|
||||
|
||||
@@ -432,7 +432,8 @@ class FixtureRequest(FuncargnamesCompatAttr):
|
||||
from _pytest import deprecated
|
||||
warnings.warn(
|
||||
deprecated.GETFUNCARGVALUE,
|
||||
DeprecationWarning)
|
||||
DeprecationWarning,
|
||||
stacklevel=2)
|
||||
return self.getfixturevalue(argname)
|
||||
|
||||
def _get_active_fixturedef(self, argname):
|
||||
@@ -956,11 +957,7 @@ class FixtureManager:
|
||||
|
||||
def getfixtureinfo(self, node, func, cls, funcargs=True):
|
||||
if funcargs and not hasattr(node, "nofuncargs"):
|
||||
if cls is not None:
|
||||
startindex = 1
|
||||
else:
|
||||
startindex = None
|
||||
argnames = getfuncargnames(func, startindex)
|
||||
argnames = getfuncargnames(func, cls=cls)
|
||||
else:
|
||||
argnames = ()
|
||||
usefixtures = getattr(func, "usefixtures", None)
|
||||
|
||||
@@ -91,7 +91,8 @@ def pytest_addoption(parser):
|
||||
"where all names are substring-matched against test names "
|
||||
"and their parent classes. Example: -k 'test_method or test_"
|
||||
"other' matches all test functions and classes whose name "
|
||||
"contains 'test_method' or 'test_other'. "
|
||||
"contains 'test_method' or 'test_other', while -k 'not test_method' "
|
||||
"matches those that don't contain 'test_method' in their names. "
|
||||
"Additionally keywords are matched to classes and functions "
|
||||
"containing extra names in their 'extra_keyword_matches' set, "
|
||||
"as well as functions which have names assigned directly to them."
|
||||
@@ -330,7 +331,7 @@ class MarkDecorator:
|
||||
return self.name # for backward-compat (2.4.1 had this attr)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.mark == other.mark
|
||||
return self.mark == other.mark if isinstance(other, MarkDecorator) else False
|
||||
|
||||
def __repr__(self):
|
||||
return "<MarkDecorator %r>" % (self.mark,)
|
||||
|
||||
@@ -381,13 +381,17 @@ class RunResult:
|
||||
return d
|
||||
raise ValueError("Pytest terminal report not found")
|
||||
|
||||
def assert_outcomes(self, passed=0, skipped=0, failed=0):
|
||||
def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0):
|
||||
""" assert that the specified outcomes appear with the respective
|
||||
numbers (0 means it didn't occur) in the text output from a test run."""
|
||||
d = self.parseoutcomes()
|
||||
assert passed == d.get("passed", 0)
|
||||
assert skipped == d.get("skipped", 0)
|
||||
assert failed == d.get("failed", 0)
|
||||
obtained = {
|
||||
'passed': d.get('passed', 0),
|
||||
'skipped': d.get('skipped', 0),
|
||||
'failed': d.get('failed', 0),
|
||||
'error': d.get('error', 0),
|
||||
}
|
||||
assert obtained == dict(passed=passed, skipped=skipped, failed=failed, error=error)
|
||||
|
||||
|
||||
class Testdir:
|
||||
|
||||
@@ -979,50 +979,48 @@ def _show_fixtures_per_test(config, session):
|
||||
tw = _pytest.config.create_terminal_writer(config)
|
||||
verbose = config.getvalue("verbose")
|
||||
|
||||
def get_best_rel(func):
|
||||
def get_best_relpath(func):
|
||||
loc = getlocation(func, curdir)
|
||||
return curdir.bestrelpath(loc)
|
||||
|
||||
def write_fixture(fixture_def):
|
||||
argname = fixture_def.argname
|
||||
|
||||
if verbose <= 0 and argname.startswith("_"):
|
||||
return
|
||||
if verbose > 0:
|
||||
bestrel = get_best_rel(fixture_def.func)
|
||||
bestrel = get_best_relpath(fixture_def.func)
|
||||
funcargspec = "{0} -- {1}".format(argname, bestrel)
|
||||
else:
|
||||
funcargspec = argname
|
||||
tw.line(funcargspec, green=True)
|
||||
|
||||
fixture_doc = fixture_def.func.__doc__
|
||||
|
||||
if fixture_doc:
|
||||
write_docstring(tw, fixture_doc)
|
||||
else:
|
||||
tw.line(' no docstring available', red=True)
|
||||
|
||||
def write_item(item):
|
||||
name2fixturedefs = item._fixtureinfo.name2fixturedefs
|
||||
|
||||
if not name2fixturedefs:
|
||||
# The given test item does not use any fixtures
|
||||
try:
|
||||
info = item._fixtureinfo
|
||||
except AttributeError:
|
||||
# doctests items have no _fixtureinfo attribute
|
||||
return
|
||||
if not info.name2fixturedefs:
|
||||
# this test item does not use any fixtures
|
||||
return
|
||||
bestrel = get_best_rel(item.function)
|
||||
|
||||
tw.line()
|
||||
tw.sep('-', 'fixtures used by {0}'.format(item.name))
|
||||
tw.sep('-', '({0})'.format(bestrel))
|
||||
for argname, fixture_defs in sorted(name2fixturedefs.items()):
|
||||
assert fixture_defs is not None
|
||||
if not fixture_defs:
|
||||
tw.sep('-', '({0})'.format(get_best_relpath(item.function)))
|
||||
# dict key not used in loop but needed for sorting
|
||||
for _, fixturedefs in sorted(info.name2fixturedefs.items()):
|
||||
assert fixturedefs is not None
|
||||
if not fixturedefs:
|
||||
continue
|
||||
# The last fixture def item in the list is expected
|
||||
# to be the one used by the test item
|
||||
write_fixture(fixture_defs[-1])
|
||||
# last item is expected to be the one used by the test item
|
||||
write_fixture(fixturedefs[-1])
|
||||
|
||||
for item in session.items:
|
||||
write_item(item)
|
||||
for session_item in session.items:
|
||||
write_item(session_item)
|
||||
|
||||
|
||||
def showfixtures(config):
|
||||
|
||||
@@ -493,7 +493,8 @@ def raises(expected_exception, *args, **kwargs):
|
||||
...
|
||||
>>> assert exc_info.type == ValueError
|
||||
|
||||
Or you can use the keyword argument ``match`` to assert that the
|
||||
|
||||
Since version ``3.1`` you can use the keyword argument ``match`` to assert that the
|
||||
exception matches a text or regex::
|
||||
|
||||
>>> with raises(ValueError, match='must be 0 or None'):
|
||||
@@ -502,7 +503,12 @@ def raises(expected_exception, *args, **kwargs):
|
||||
>>> with raises(ValueError, match=r'must be \d+$'):
|
||||
... raise ValueError("value must be 42")
|
||||
|
||||
Or you can specify a callable by passing a to-be-called lambda::
|
||||
**Legacy forms**
|
||||
|
||||
The forms below are fully supported but are discouraged for new code because the
|
||||
context manager form is regarded as more readable and less error-prone.
|
||||
|
||||
It is possible to specify a callable by passing a to-be-called lambda::
|
||||
|
||||
>>> raises(ZeroDivisionError, lambda: 1/0)
|
||||
<ExceptionInfo ...>
|
||||
@@ -516,11 +522,14 @@ def raises(expected_exception, *args, **kwargs):
|
||||
>>> raises(ZeroDivisionError, f, x=0)
|
||||
<ExceptionInfo ...>
|
||||
|
||||
A third possibility is to use a string to be executed::
|
||||
It is also possible to pass a string to be evaluated at runtime::
|
||||
|
||||
>>> raises(ZeroDivisionError, "f(0)")
|
||||
<ExceptionInfo ...>
|
||||
|
||||
The string will be evaluated using the same ``locals()`` and ``globals()``
|
||||
at the moment of the ``raises`` call.
|
||||
|
||||
.. autoclass:: _pytest._code.ExceptionInfo
|
||||
:members:
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import sys
|
||||
from time import time
|
||||
|
||||
import py
|
||||
from _pytest.compat import _PY2
|
||||
from _pytest._code.code import TerminalRepr, ExceptionInfo
|
||||
from _pytest.outcomes import skip, Skipped, TEST_OUTCOME
|
||||
|
||||
@@ -134,7 +135,11 @@ def _update_current_test_var(item, when):
|
||||
"""
|
||||
var_name = 'PYTEST_CURRENT_TEST'
|
||||
if when:
|
||||
os.environ[var_name] = '{0} ({1})'.format(item.nodeid, when)
|
||||
value = '{0} ({1})'.format(item.nodeid, when)
|
||||
if _PY2:
|
||||
# python 2 doesn't like null bytes on environment variables (see #2644)
|
||||
value = value.replace('\x00', '(null)')
|
||||
os.environ[var_name] = value
|
||||
else:
|
||||
os.environ.pop(var_name)
|
||||
|
||||
|
||||
@@ -180,8 +180,22 @@ class TerminalReporter:
|
||||
self._tw.line(line, **markup)
|
||||
|
||||
def rewrite(self, line, **markup):
|
||||
"""
|
||||
Rewinds the terminal cursor to the beginning and writes the given line.
|
||||
|
||||
:kwarg erase: if True, will also add spaces until the full terminal width to ensure
|
||||
previous lines are properly erased.
|
||||
|
||||
The rest of the keyword arguments are markup instructions.
|
||||
"""
|
||||
erase = markup.pop('erase', False)
|
||||
if erase:
|
||||
fill_count = self._tw.fullwidth - len(line)
|
||||
fill = ' ' * fill_count
|
||||
else:
|
||||
fill = ''
|
||||
line = str(line)
|
||||
self._tw.write("\r" + line, **markup)
|
||||
self._tw.write("\r" + line + fill, **markup)
|
||||
|
||||
def write_sep(self, sep, title=None, **markup):
|
||||
self.ensure_newline()
|
||||
@@ -292,12 +306,9 @@ class TerminalReporter:
|
||||
if skipped:
|
||||
line += " / %d skipped" % skipped
|
||||
if self.isatty:
|
||||
self.rewrite(line, bold=True, erase=True)
|
||||
if final:
|
||||
line += " \n"
|
||||
# Rewrite with empty line so we will not see the artifact of
|
||||
# previous write
|
||||
self.rewrite('')
|
||||
self.rewrite(line, bold=True)
|
||||
self.write('\n')
|
||||
else:
|
||||
self.write_line(line)
|
||||
|
||||
|
||||
12
appveyor.yml
12
appveyor.yml
@@ -21,13 +21,13 @@ environment:
|
||||
- TOXENV: "py27-xdist"
|
||||
- TOXENV: "py27-trial"
|
||||
- TOXENV: "py27-numpy"
|
||||
- TOXENV: "py35-pexpect"
|
||||
- TOXENV: "py35-xdist"
|
||||
- TOXENV: "py35-trial"
|
||||
- TOXENV: "py35-numpy"
|
||||
- TOXENV: "py36-pexpect"
|
||||
- TOXENV: "py36-xdist"
|
||||
- TOXENV: "py36-trial"
|
||||
- TOXENV: "py36-numpy"
|
||||
- TOXENV: "py27-nobyte"
|
||||
- TOXENV: "doctesting"
|
||||
- TOXENV: "freeze"
|
||||
- TOXENV: "py35-freeze"
|
||||
- TOXENV: "docs"
|
||||
|
||||
install:
|
||||
@@ -36,7 +36,7 @@ install:
|
||||
|
||||
- if "%TOXENV%" == "pypy" call scripts\install-pypy.bat
|
||||
|
||||
- C:\Python35\python -m pip install tox
|
||||
- C:\Python36\python -m pip install --upgrade --pre tox
|
||||
|
||||
build: false # Not a C# project, build stuff at the test step instead.
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ Release announcements
|
||||
:maxdepth: 2
|
||||
|
||||
|
||||
release-3.2.3
|
||||
release-3.2.2
|
||||
release-3.2.1
|
||||
release-3.2.0
|
||||
release-3.1.3
|
||||
release-3.1.2
|
||||
|
||||
22
doc/en/announce/release-3.2.1.rst
Normal file
22
doc/en/announce/release-3.2.1.rst
Normal file
@@ -0,0 +1,22 @@
|
||||
pytest-3.2.1
|
||||
=======================================
|
||||
|
||||
pytest 3.2.1 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at http://doc.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Alex Gaynor
|
||||
* Bruno Oliveira
|
||||
* Florian Bruhin
|
||||
* Ronny Pfannschmidt
|
||||
* Srinivas Reddy Thatiparthy
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
28
doc/en/announce/release-3.2.2.rst
Normal file
28
doc/en/announce/release-3.2.2.rst
Normal file
@@ -0,0 +1,28 @@
|
||||
pytest-3.2.2
|
||||
=======================================
|
||||
|
||||
pytest 3.2.2 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at http://doc.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Andreas Pelme
|
||||
* Antonio Hidalgo
|
||||
* Bruno Oliveira
|
||||
* Felipe Dau
|
||||
* Fernando Macedo
|
||||
* Jesús Espino
|
||||
* Joan Massich
|
||||
* Joe Talbott
|
||||
* Kirill Pinchuk
|
||||
* Ronny Pfannschmidt
|
||||
* Xuan Luong
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
23
doc/en/announce/release-3.2.3.rst
Normal file
23
doc/en/announce/release-3.2.3.rst
Normal file
@@ -0,0 +1,23 @@
|
||||
pytest-3.2.3
|
||||
=======================================
|
||||
|
||||
pytest 3.2.3 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at http://doc.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Bruno Oliveira
|
||||
* Evan
|
||||
* Joe Hamman
|
||||
* Oliver Bestwalter
|
||||
* Ronny Pfannschmidt
|
||||
* Xuan Luong
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
@@ -119,9 +119,9 @@ exceptions your own code is deliberately raising, whereas using
|
||||
like documenting unfixed bugs (where the test describes what "should" happen)
|
||||
or bugs in dependencies.
|
||||
|
||||
If you want to test that a regular expression matches on the string
|
||||
representation of an exception (like the ``TestCase.assertRaisesRegexp`` method
|
||||
from ``unittest``) you can use the ``ExceptionInfo.match`` method::
|
||||
Also, the context manager form accepts a ``match`` keyword parameter to test
|
||||
that a regular expression matches on the string representation of an exception
|
||||
(like the ``TestCase.assertRaisesRegexp`` method from ``unittest``)::
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -129,12 +129,11 @@ from ``unittest``) you can use the ``ExceptionInfo.match`` method::
|
||||
raise ValueError("Exception 123 raised")
|
||||
|
||||
def test_match():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
with pytest.raises(ValueError, match=r'.* 123 .*'):
|
||||
myfunc()
|
||||
excinfo.match(r'.* 123 .*')
|
||||
|
||||
The regexp parameter of the ``match`` method is matched with the ``re.search``
|
||||
function. So in the above example ``excinfo.match('123')`` would have worked as
|
||||
function. So in the above example ``match='123'`` would have worked as
|
||||
well.
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ Full pytest documentation
|
||||
historical-notes
|
||||
license
|
||||
contributing
|
||||
development_guide
|
||||
talks
|
||||
projects
|
||||
faq
|
||||
|
||||
@@ -230,13 +230,16 @@ Builtin configuration file options
|
||||
.. confval:: python_files
|
||||
|
||||
One or more Glob-style file patterns determining which python files
|
||||
are considered as test modules.
|
||||
are considered as test modules. By default, pytest will consider
|
||||
any file matching with ``test_*.py`` and ``*_test.py`` globs as a test
|
||||
module.
|
||||
|
||||
.. confval:: python_classes
|
||||
|
||||
One or more name prefixes or glob-style patterns determining which classes
|
||||
are considered for test collection. Here is an example of how to collect
|
||||
tests from classes that end in ``Suite``:
|
||||
are considered for test collection. By default, pytest will consider any
|
||||
class prefixed with ``Test`` as a test collection. Here is an example of how
|
||||
to collect tests from classes that end in ``Suite``:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
@@ -251,7 +254,8 @@ Builtin configuration file options
|
||||
.. confval:: python_functions
|
||||
|
||||
One or more name prefixes or glob-patterns determining which test functions
|
||||
and methods are considered tests. Here is an example of how
|
||||
and methods are considered tests. By default, pytest will consider any
|
||||
function prefixed with ``test`` as a test. Here is an example of how
|
||||
to collect test functions and methods that end in ``_test``:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
108
doc/en/development_guide.rst
Normal file
108
doc/en/development_guide.rst
Normal file
@@ -0,0 +1,108 @@
|
||||
=================
|
||||
Development Guide
|
||||
=================
|
||||
|
||||
Some general guidelines regarding development in pytest for core maintainers and general contributors. Nothing here
|
||||
is set in stone and can't be changed, feel free to suggest improvements or changes in the workflow.
|
||||
|
||||
|
||||
Code Style
|
||||
----------
|
||||
|
||||
* `PEP-8 <https://www.python.org/dev/peps/pep-0008>`_
|
||||
* `flake8 <https://pypi.python.org/pypi/flake8>`_ for quality checks
|
||||
* `invoke <http://www.pyinvoke.org/>`_ to automate development tasks
|
||||
|
||||
|
||||
Branches
|
||||
--------
|
||||
|
||||
We have two long term branches:
|
||||
|
||||
* ``master``: contains the code for the next bugfix release.
|
||||
* ``features``: contains the code with new features for the next minor release.
|
||||
|
||||
The official repository usually does not contain topic branches, developers and contributors should create topic
|
||||
branches in their own forks.
|
||||
|
||||
Exceptions can be made for cases where more than one contributor is working on the same
|
||||
topic or where it makes sense to use some automatic capability of the main repository, such as automatic docs from
|
||||
`readthedocs <readthedocs.org>`_ for a branch dealing with documentation refactoring.
|
||||
|
||||
Issues
|
||||
------
|
||||
|
||||
Any question, feature, bug or proposal is welcome as an issue. Users are encouraged to use them whenever they need.
|
||||
|
||||
GitHub issues should use labels to categorize them. Labels should be created sporadically, to fill a niche; we should
|
||||
avoid creating labels just for the sake of creating them.
|
||||
|
||||
Here is a list of labels and a brief description mentioning their intent.
|
||||
|
||||
|
||||
**Type**
|
||||
|
||||
* ``type: backward compatibility``: issue that will cause problems with old pytest versions.
|
||||
* ``type: bug``: problem that needs to be addressed.
|
||||
* ``type: deprecation``: feature that will be deprecated in the future.
|
||||
* ``type: docs``: documentation missing or needing clarification.
|
||||
* ``type: enhancement``: new feature or API change, should be merged into ``features``.
|
||||
* ``type: feature-branch``: new feature or API change, should be merged into ``features``.
|
||||
* ``type: infrastructure``: improvement to development/releases/CI structure.
|
||||
* ``type: performance``: performance or memory problem/improvement.
|
||||
* ``type: proposal``: proposal for a new feature, often to gather opinions or design the API around the new feature.
|
||||
* ``type: question``: question regarding usage, installation, internals or how to test something.
|
||||
* ``type: refactoring``: internal improvements to the code.
|
||||
* ``type: regression``: indicates a problem that was introduced in a release which was working previously.
|
||||
|
||||
**Status**
|
||||
|
||||
* ``status: critical``: grave problem or usability issue that affects lots of users.
|
||||
* ``status: easy``: easy issue that is friendly to new contributors.
|
||||
* ``status: help wanted``: core developers need help from experts on this topic.
|
||||
* ``status: needs information``: reporter needs to provide more information; can be closed after 2 or more weeks of inactivity.
|
||||
|
||||
**Topic**
|
||||
|
||||
* ``topic: collection``
|
||||
* ``topic: fixtures``
|
||||
* ``topic: parametrize``
|
||||
* ``topic: reporting``
|
||||
* ``topic: selection``
|
||||
* ``topic: tracebacks``
|
||||
|
||||
**Plugin (internal or external)**
|
||||
|
||||
* ``plugin: cache``
|
||||
* ``plugin: capture``
|
||||
* ``plugin: doctests``
|
||||
* ``plugin: junitxml``
|
||||
* ``plugin: monkeypatch``
|
||||
* ``plugin: nose``
|
||||
* ``plugin: pastebin``
|
||||
* ``plugin: pytester``
|
||||
* ``plugin: tmpdir``
|
||||
* ``plugin: unittest``
|
||||
* ``plugin: warnings``
|
||||
* ``plugin: xdist``
|
||||
|
||||
|
||||
**OS**
|
||||
|
||||
Issues specific to a single operating system. Do not use as a means to indicate where an issue originated from, only
|
||||
for problems that happen **only** in that system.
|
||||
|
||||
* ``os: linux``
|
||||
* ``os: mac``
|
||||
* ``os: windows``
|
||||
|
||||
**Temporary**
|
||||
|
||||
Used to classify issues for limited time, to help find issues related in events for example.
|
||||
They should be removed after they are no longer relevant.
|
||||
|
||||
* ``temporary: EP2017 sprint``:
|
||||
* ``temporary: sprint-candidate``:
|
||||
|
||||
|
||||
.. include:: ../../HOWTORELEASE.rst
|
||||
@@ -395,6 +395,49 @@ The ``--markers`` option always gives you a list of available markers::
|
||||
@pytest.mark.trylast: mark a hook implementation function such that the plugin machinery will try to call it last/as late as possible.
|
||||
|
||||
|
||||
.. _`passing callables to custom markers`:
|
||||
|
||||
Passing a callable to custom markers
|
||||
--------------------------------------------
|
||||
|
||||
.. regendoc:wipe
|
||||
|
||||
Below is the config file that will be used in the next examples::
|
||||
|
||||
# content of conftest.py
|
||||
import sys
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
marker = item.get_marker('my_marker')
|
||||
if marker is not None:
|
||||
for info in marker:
|
||||
print('Marker info name={} args={} kwars={}'.format(info.name, info.args, info.kwargs))
|
||||
sys.stdout.flush()
|
||||
|
||||
A custom marker can have its argument set, i.e. ``args`` and ``kwargs`` properties, defined by either invoking it as a callable or using ``pytest.mark.MARKER_NAME.with_args``. These two methods achieve the same effect most of the time.
|
||||
|
||||
However, if there is a callable as the single positional argument with no keyword arguments, using the ``pytest.mark.MARKER_NAME(c)`` will not pass ``c`` as a positional argument but decorate ``c`` with the custom marker (see :ref:`MarkDecorator <mark>`). Fortunately, ``pytest.mark.MARKER_NAME.with_args`` comes to the rescue::
|
||||
|
||||
# content of test_custom_marker.py
|
||||
import pytest
|
||||
|
||||
def hello_world(*args, **kwargs):
|
||||
return 'Hello World'
|
||||
|
||||
@pytest.mark.my_marker.with_args(hello_world)
|
||||
def test_with_args():
|
||||
pass
|
||||
|
||||
The output is as follows::
|
||||
|
||||
$ pytest -q -s
|
||||
Marker info name=my_marker args=(<function hello_world at 0xdeadbeef>,) kwars={}
|
||||
.
|
||||
1 passed in 0.12 seconds
|
||||
|
||||
We can see that the custom marker has its argument set extended with the function ``hello_world``. This is the key difference between creating a custom marker as a callable, which invokes ``__call__`` behind the scenes, and using ``with_args``.
|
||||
|
||||
|
||||
Reading markers which were set from multiple places
|
||||
----------------------------------------------------
|
||||
|
||||
|
||||
@@ -358,7 +358,7 @@ get on the terminal - we are working on that)::
|
||||
> int(s)
|
||||
E ValueError: invalid literal for int() with base 10: 'qwe'
|
||||
|
||||
<0-codegen $PYTHON_PREFIX/lib/python3.5/site-packages/_pytest/python_api.py:570>:1: ValueError
|
||||
<0-codegen $PYTHON_PREFIX/lib/python3.5/site-packages/_pytest/python_api.py:579>:1: ValueError
|
||||
_______ TestRaises.test_raises_doesnt ________
|
||||
|
||||
self = <failure_demo.TestRaises object at 0xdeadbeef>
|
||||
|
||||
@@ -127,7 +127,7 @@ Control skipping of tests according to command line option
|
||||
.. regendoc:wipe
|
||||
|
||||
Here is a ``conftest.py`` file adding a ``--runslow`` command
|
||||
line option to control skipping of ``slow`` marked tests:
|
||||
line option to control skipping of ``pytest.mark.slow`` marked tests:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -136,7 +136,16 @@ line option to control skipping of ``slow`` marked tests:
|
||||
import pytest
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--runslow", action="store_true",
|
||||
help="run slow tests")
|
||||
default=False, help="run slow tests")
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
if config.getoption("--runslow"):
|
||||
# --runslow given in cli: do not skip slow tests
|
||||
return
|
||||
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
|
||||
for item in items:
|
||||
if "slow" in item.keywords:
|
||||
item.add_marker(skip_slow)
|
||||
|
||||
We can now write a test module like this:
|
||||
|
||||
@@ -146,17 +155,11 @@ We can now write a test module like this:
|
||||
import pytest
|
||||
|
||||
|
||||
slow = pytest.mark.skipif(
|
||||
not pytest.config.getoption("--runslow"),
|
||||
reason="need --runslow option to run"
|
||||
)
|
||||
|
||||
|
||||
def test_func_fast():
|
||||
pass
|
||||
|
||||
|
||||
@slow
|
||||
@pytest.mark.slow
|
||||
def test_func_slow():
|
||||
pass
|
||||
|
||||
@@ -170,7 +173,7 @@ and when running it will see a skipped "slow" test::
|
||||
|
||||
test_module.py .s
|
||||
======= short test summary info ========
|
||||
SKIP [1] test_module.py:14: need --runslow option to run
|
||||
SKIP [1] test_module.py:8: need --runslow option to run
|
||||
|
||||
======= 1 passed, 1 skipped in 0.12 seconds ========
|
||||
|
||||
@@ -363,14 +366,14 @@ out which tests are the slowest. Let's make an artificial test suite:
|
||||
import time
|
||||
|
||||
def test_funcfast():
|
||||
pass
|
||||
|
||||
def test_funcslow1():
|
||||
time.sleep(0.1)
|
||||
|
||||
def test_funcslow2():
|
||||
def test_funcslow1():
|
||||
time.sleep(0.2)
|
||||
|
||||
def test_funcslow2():
|
||||
time.sleep(0.3)
|
||||
|
||||
Now we can profile which test functions execute the slowest::
|
||||
|
||||
$ pytest --durations=3
|
||||
@@ -382,9 +385,9 @@ Now we can profile which test functions execute the slowest::
|
||||
test_some_are_slow.py ...
|
||||
|
||||
======= slowest 3 test durations ========
|
||||
0.20s call test_some_are_slow.py::test_funcslow2
|
||||
0.10s call test_some_are_slow.py::test_funcslow1
|
||||
0.00s setup test_some_are_slow.py::test_funcfast
|
||||
0.30s call test_some_are_slow.py::test_funcslow2
|
||||
0.20s call test_some_are_slow.py::test_funcslow1
|
||||
0.10s call test_some_are_slow.py::test_funcfast
|
||||
======= 3 passed in 0.12 seconds ========
|
||||
|
||||
incremental testing - test steps
|
||||
|
||||
@@ -122,7 +122,7 @@ want to distribute them along with your application::
|
||||
test_view.py
|
||||
...
|
||||
|
||||
In this scheme, it is easy to your run tests using the ``--pyargs`` option::
|
||||
In this scheme, it is easy to run your tests using the ``--pyargs`` option::
|
||||
|
||||
pytest --pyargs mypkg
|
||||
|
||||
@@ -267,7 +267,7 @@ your own setuptools Test command for invoking pytest.
|
||||
|
||||
def initialize_options(self):
|
||||
TestCommand.initialize_options(self)
|
||||
self.pytest_args = []
|
||||
self.pytest_args = ''
|
||||
|
||||
def run_tests(self):
|
||||
import shlex
|
||||
|
||||
@@ -59,7 +59,7 @@ Features
|
||||
|
||||
- Python2.6+, Python3.3+, PyPy-2.3, Jython-2.5 (untested);
|
||||
|
||||
- Rich plugin architecture, with over 150+ :ref:`external plugins <extplugins>` and thriving community;
|
||||
- Rich plugin architecture, with over 315+ `external plugins <http://plugincompat.herokuapp.com>`_ and thriving community;
|
||||
|
||||
|
||||
Documentation
|
||||
|
||||
@@ -10,6 +10,7 @@ By using the ``pytest.mark`` helper you can easily set
|
||||
metadata on your test functions. There are
|
||||
some builtin markers, for example:
|
||||
|
||||
* :ref:`skip <skip>` - always skip a test function
|
||||
* :ref:`skipif <skipif>` - skip a test function if a certain condition is met
|
||||
* :ref:`xfail <xfail>` - produce an "expected failure" outcome if a certain
|
||||
condition is met
|
||||
|
||||
@@ -198,6 +198,9 @@ list::
|
||||
SKIP [1] test_strings.py:2: got empty parameter set ['stringinput'], function test_valid_string at $REGENDOC_TMPDIR/test_strings.py:1
|
||||
1 skipped in 0.12 seconds
|
||||
|
||||
Note that when calling ``metafunc.parametrize`` multiple times with different parameter sets, all parameter names across
|
||||
those sets cannot be duplicated, otherwise an error will be raised.
|
||||
|
||||
For further examples, you might want to look at :ref:`more
|
||||
parametrization examples <paramexamples>`.
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ corresponding to the "short" letters shown in the test progress::
|
||||
(See :ref:`how to change command line options defaults`)
|
||||
|
||||
.. _skipif:
|
||||
.. _skip:
|
||||
.. _`condition booleans`:
|
||||
|
||||
Skipping test functions
|
||||
@@ -53,7 +54,7 @@ by calling the ``pytest.skip(reason)`` function:
|
||||
if not valid_config():
|
||||
pytest.skip("unsupported configuration")
|
||||
|
||||
The imperative method is useful when it is not possible to evaluate the skip condition
|
||||
The imperative method is useful when it is not possible to evaluate the skip condition
|
||||
during import time.
|
||||
|
||||
``skipif``
|
||||
@@ -72,7 +73,7 @@ when run on a Python3.3 interpreter::
|
||||
...
|
||||
|
||||
If the condition evaluates to ``True`` during collection, the test function will be skipped,
|
||||
with the specified reason appearing in the summary when using ``-rs``.
|
||||
with the specified reason appearing in the summary when using ``-rs``.
|
||||
|
||||
You can share ``skipif`` markers between modules. Consider this test module::
|
||||
|
||||
@@ -117,6 +118,12 @@ You can use the ``skipif`` marker (as any other marker) on classes::
|
||||
If the condition is ``True``, this marker will produce a skip result for
|
||||
each of the test methods of that class.
|
||||
|
||||
.. warning::
|
||||
|
||||
The use of ``skipif`` on classes that use inheritance is strongly
|
||||
discouraged. `A Known bug <https://github.com/pytest-dev/pytest/issues/568>`_
|
||||
in pytest's markers may cause unexpected behavior in super classes.
|
||||
|
||||
If you want to skip all test functions of a module, you may use
|
||||
the ``pytestmark`` name on the global level:
|
||||
|
||||
@@ -345,5 +352,3 @@ test instances when using parametrize:
|
||||
])
|
||||
def test_increment(n, expected):
|
||||
assert n + 1 == expected
|
||||
|
||||
|
||||
|
||||
@@ -2,58 +2,77 @@
|
||||
.. _`unittest.TestCase`:
|
||||
.. _`unittest`:
|
||||
|
||||
Support for unittest.TestCase / Integration of fixtures
|
||||
=====================================================================
|
||||
unittest.TestCase Support
|
||||
=========================
|
||||
|
||||
.. _`unittest.py style`: http://docs.python.org/library/unittest.html
|
||||
``pytest`` supports running Python ``unittest``-based tests out of the box.
|
||||
It's meant for leveraging existing ``unittest``-based test suites
|
||||
to use pytest as a test runner and also allow to incrementally adapt
|
||||
the test suite to take full advantage of pytest's features.
|
||||
|
||||
``pytest`` has support for running Python `unittest.py style`_ tests.
|
||||
It's meant for leveraging existing unittest-style projects
|
||||
to use pytest features. Concretely, pytest will automatically
|
||||
collect ``unittest.TestCase`` subclasses and their ``test`` methods in
|
||||
test files. It will invoke typical setup/teardown methods and
|
||||
generally try to make test suites written to run on unittest, to also
|
||||
run using ``pytest``. We assume here that you are familiar with writing
|
||||
``unittest.TestCase`` style tests and rather focus on
|
||||
integration aspects.
|
||||
To run an existing ``unittest``-style test suite using ``pytest``, type::
|
||||
|
||||
Note that this is meant as a provisional way of running your test code
|
||||
until you fully convert to pytest-style tests. To fully take advantage of
|
||||
:ref:`fixtures <fixture>`, :ref:`parametrization <parametrize>` and
|
||||
:ref:`hooks <writing-plugins>` you should convert (tools like `unittest2pytest
|
||||
<https://pypi.python.org/pypi/unittest2pytest/>`__ are helpful).
|
||||
Also, not all 3rd party pluging are expected to work best with
|
||||
``unittest.TestCase`` style tests.
|
||||
pytest tests
|
||||
|
||||
Usage
|
||||
-------------------------------------------------------------------
|
||||
|
||||
After :ref:`installation` type::
|
||||
pytest will automatically collect ``unittest.TestCase`` subclasses and
|
||||
their ``test`` methods in ``test_*.py`` or ``*_test.py`` files.
|
||||
|
||||
pytest
|
||||
Almost all ``unittest`` features are supported:
|
||||
|
||||
and you should be able to run your unittest-style tests if they
|
||||
are contained in ``test_*`` modules. If that works for you then
|
||||
you can make use of most :ref:`pytest features <features>`, for example
|
||||
``--pdb`` debugging in failures, using :ref:`plain assert-statements <assert>`,
|
||||
:ref:`more informative tracebacks <tbreportdemo>`, stdout-capturing or
|
||||
distributing tests to multiple CPUs via the ``-nNUM`` option if you
|
||||
installed the ``pytest-xdist`` plugin. Please refer to
|
||||
the general ``pytest`` documentation for many more examples.
|
||||
* ``@unittest.skip`` style decorators;
|
||||
* ``setUp/tearDown``;
|
||||
* ``setUpClass/tearDownClass()``;
|
||||
|
||||
.. note::
|
||||
.. _`load_tests protocol`: https://docs.python.org/3/library/unittest.html#load-tests-protocol
|
||||
.. _`setUpModule/tearDownModule`: https://docs.python.org/3/library/unittest.html#setupmodule-and-teardownmodule
|
||||
.. _`subtests`: https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests
|
||||
|
||||
Running tests from ``unittest.TestCase`` subclasses with ``--pdb`` will
|
||||
disable tearDown and cleanup methods for the case that an Exception
|
||||
occurs. This allows proper post mortem debugging for all applications
|
||||
which have significant logic in their tearDown machinery. However,
|
||||
supporting this feature has the following side effect: If people
|
||||
overwrite ``unittest.TestCase`` ``__call__`` or ``run``, they need to
|
||||
to overwrite ``debug`` in the same way (this is also true for standard
|
||||
unittest).
|
||||
Up to this point pytest does not have support for the following features:
|
||||
|
||||
Mixing pytest fixtures into unittest.TestCase style tests
|
||||
-----------------------------------------------------------
|
||||
* `load_tests protocol`_;
|
||||
* `setUpModule/tearDownModule`_;
|
||||
* `subtests`_;
|
||||
|
||||
Benefits out of the box
|
||||
-----------------------
|
||||
|
||||
By running your test suite with pytest you can make use of several features,
|
||||
in most cases without having to modify existing code:
|
||||
|
||||
* Obtain :ref:`more informative tracebacks <tbreportdemo>`;
|
||||
* :ref:`stdout and stderr <captures>` capturing;
|
||||
* :ref:`Test selection options <select-tests>` using ``-k`` and ``-m`` flags;
|
||||
* :ref:`maxfail`;
|
||||
* :ref:`--pdb <pdb-option>` command-line option for debugging on test failures
|
||||
(see :ref:`note <pdb-unittest-note>` below);
|
||||
* Distribute tests to multiple CPUs using the `pytest-xdist <http://pypi.python.org/pypi/pytest-xdist>`_ plugin;
|
||||
* Use :ref:`plain assert-statements <assert>` instead of ``self.assert*`` functions (`unittest2pytest
|
||||
<https://pypi.python.org/pypi/unittest2pytest/>`__ is immensely helpful in this);
|
||||
|
||||
|
||||
pytest features in ``unittest.TestCase`` subclasses
|
||||
---------------------------------------------------
|
||||
|
||||
The following pytest features work in ``unittest.TestCase`` subclasses:
|
||||
|
||||
* :ref:`Marks <mark>`: :ref:`skip <skip>`, :ref:`skipif <skipif>`, :ref:`xfail <xfail>`;
|
||||
* :ref:`Auto-use fixtures <mixing-fixtures>`;
|
||||
|
||||
The following pytest features **do not** work, and probably
|
||||
never will due to different design philosophies:
|
||||
|
||||
* :ref:`Fixtures <fixture>` (except for ``autouse`` fixtures, see :ref:`below <mixing-fixtures>`);
|
||||
* :ref:`Parametrization <parametrize>`;
|
||||
* :ref:`Custom hooks <writing-plugins>`;
|
||||
|
||||
|
||||
Third party plugins may or may not work well, depending on the plugin and the test suite.
|
||||
|
||||
.. _mixing-fixtures:
|
||||
|
||||
Mixing pytest fixtures into ``unittest.TestCase`` subclasses using marks
|
||||
------------------------------------------------------------------------
|
||||
|
||||
Running your unittest with ``pytest`` allows you to use its
|
||||
:ref:`fixture mechanism <fixture>` with ``unittest.TestCase`` style
|
||||
@@ -143,8 +162,8 @@ share the same ``self.db`` instance which was our intention
|
||||
when writing the class-scoped fixture function above.
|
||||
|
||||
|
||||
autouse fixtures and accessing other fixtures
|
||||
-------------------------------------------------------------------
|
||||
Using autouse fixtures and accessing other fixtures
|
||||
---------------------------------------------------
|
||||
|
||||
Although it's usually better to explicitly declare use of fixtures you need
|
||||
for a given test, you may sometimes want to have fixtures that are
|
||||
@@ -165,6 +184,7 @@ creation of a per-test temporary directory::
|
||||
import unittest
|
||||
|
||||
class MyTest(unittest.TestCase):
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def initdir(self, tmpdir):
|
||||
tmpdir.chdir() # change to pytest-provided temporary directory
|
||||
@@ -200,3 +220,16 @@ was executed ahead of the ``test_method``.
|
||||
|
||||
You can also gradually move away from subclassing from ``unittest.TestCase`` to *plain asserts*
|
||||
and then start to benefit from the full pytest feature set step by step.
|
||||
|
||||
.. _pdb-unittest-note:
|
||||
|
||||
.. note::
|
||||
|
||||
Running tests from ``unittest.TestCase`` subclasses with ``--pdb`` will
|
||||
disable tearDown and cleanup methods for the case that an Exception
|
||||
occurs. This allows proper post mortem debugging for all applications
|
||||
which have significant logic in their tearDown machinery. However,
|
||||
supporting this feature has the following side effect: If people
|
||||
overwrite ``unittest.TestCase`` ``__call__`` or ``run``, they need to
|
||||
to overwrite ``debug`` in the same way (this is also true for standard
|
||||
unittest).
|
||||
|
||||
@@ -41,6 +41,8 @@ Getting help on version, option names, environment variables
|
||||
pytest -h | --help # show help on command line and config file options
|
||||
|
||||
|
||||
.. _maxfail:
|
||||
|
||||
Stopping after the first (or N) failures
|
||||
---------------------------------------------------
|
||||
|
||||
@@ -49,6 +51,8 @@ To stop the testing process after the first (N) failures::
|
||||
pytest -x # stop after first failure
|
||||
pytest --maxfail=2 # stop after two failures
|
||||
|
||||
.. _select-tests:
|
||||
|
||||
Specifying tests / selecting tests
|
||||
---------------------------------------------------
|
||||
|
||||
@@ -135,6 +139,9 @@ with Ctrl+C to find out where the tests are *hanging*. By default no output
|
||||
will be shown (because KeyboardInterrupt is caught by pytest). By using this
|
||||
option you make sure a trace is shown.
|
||||
|
||||
|
||||
.. _pdb-option:
|
||||
|
||||
Dropping to PDB_ (Python Debugger) on failures
|
||||
-----------------------------------------------
|
||||
|
||||
@@ -304,6 +311,13 @@ Creating resultlog format files
|
||||
|
||||
This option is rarely used and is scheduled for removal in 4.0.
|
||||
|
||||
An alternative for users which still need similar functionality is to use the
|
||||
`pytest-tap <https://pypi.python.org/pypi/pytest-tap>`_ plugin which provides
|
||||
a stream of test data.
|
||||
|
||||
If you have any concerns, please don't hesitate to
|
||||
`open an issue <https://github.com/pytest-dev/pytest/issues>`_.
|
||||
|
||||
To create plain-text machine-readable result files you can issue::
|
||||
|
||||
pytest --resultlog=path
|
||||
|
||||
@@ -5,4 +5,4 @@ if "%TOXENV%" == "coveralls" (
|
||||
exit /b 0
|
||||
)
|
||||
)
|
||||
C:\Python35\python -m tox
|
||||
C:\Python36\python -m tox
|
||||
|
||||
@@ -400,7 +400,7 @@ class TestGeneralUsage(object):
|
||||
monkeypatch.setitem(sys.modules, 'myplugin', mod)
|
||||
assert pytest.main(args=[str(tmpdir)], plugins=['myplugin']) == 0
|
||||
|
||||
def test_parameterized_with_bytes_regex(self, testdir):
|
||||
def test_parametrized_with_bytes_regex(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
import re
|
||||
import pytest
|
||||
@@ -414,6 +414,19 @@ class TestGeneralUsage(object):
|
||||
'*1 passed*'
|
||||
])
|
||||
|
||||
def test_parametrized_with_null_bytes(self, testdir):
|
||||
"""Test parametrization with values that contain null bytes and unicode characters (#2644)"""
|
||||
p = testdir.makepyfile(u"""
|
||||
# encoding: UTF-8
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize("data", ["\\x00", u'ação'])
|
||||
def test_foo(data):
|
||||
assert data
|
||||
""")
|
||||
res = testdir.runpytest(p)
|
||||
res.assert_outcomes(passed=2)
|
||||
|
||||
|
||||
class TestInvocationVariants(object):
|
||||
def test_earlyinit(self, testdir):
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# coding: utf-8
|
||||
from __future__ import absolute_import, division, print_function
|
||||
import sys
|
||||
|
||||
import _pytest._code
|
||||
import py
|
||||
import pytest
|
||||
from test_excinfo import TWMock
|
||||
|
||||
|
||||
def test_ne():
|
||||
@@ -172,3 +174,23 @@ class TestTracebackEntry(object):
|
||||
source = entry.getsource()
|
||||
assert len(source) == 6
|
||||
assert 'assert False' in source[5]
|
||||
|
||||
|
||||
class TestReprFuncArgs(object):
|
||||
|
||||
def test_not_raise_exception_with_mixed_encoding(self):
|
||||
from _pytest._code.code import ReprFuncArgs
|
||||
|
||||
tw = TWMock()
|
||||
|
||||
args = [
|
||||
('unicode_string', u"São Paulo"),
|
||||
('utf8_string', 'S\xc3\xa3o Paulo'),
|
||||
]
|
||||
|
||||
r = ReprFuncArgs(args)
|
||||
r.toterminal(tw)
|
||||
if sys.version_info[0] >= 3:
|
||||
assert tw.lines[0] == 'unicode_string = São Paulo, utf8_string = São Paulo'
|
||||
else:
|
||||
assert tw.lines[0] == 'unicode_string = São Paulo, utf8_string = São Paulo'
|
||||
|
||||
@@ -391,7 +391,6 @@ def test_deindent():
|
||||
assert lines == ['', 'def f():', ' def g():', ' pass', ' ']
|
||||
|
||||
|
||||
@pytest.mark.xfail("sys.version_info[:3] < (2,7,0)")
|
||||
def test_source_of_class_at_eof_without_newline(tmpdir):
|
||||
# this test fails because the implicit inspect.getsource(A) below
|
||||
# does not return the "x = 1" last line.
|
||||
|
||||
@@ -78,4 +78,7 @@ def test_resultlog_is_deprecated(testdir):
|
||||
pass
|
||||
''')
|
||||
result = testdir.runpytest('--result-log=%s' % testdir.tmpdir.join('result.log'))
|
||||
result.stdout.fnmatch_lines(['*--result-log is deprecated and scheduled for removal in pytest 4.0*'])
|
||||
result.stdout.fnmatch_lines([
|
||||
'*--result-log is deprecated and scheduled for removal in pytest 4.0*',
|
||||
'*See https://docs.pytest.org/*/usage.html#creating-resultlog-format-files for more information*',
|
||||
])
|
||||
|
||||
@@ -147,11 +147,21 @@ class TestClass(object):
|
||||
])
|
||||
|
||||
def test_static_method(self, testdir):
|
||||
"""Support for collecting staticmethod tests (#2528, #2699)"""
|
||||
testdir.getmodulecol("""
|
||||
import pytest
|
||||
class Test(object):
|
||||
@staticmethod
|
||||
def test_something():
|
||||
pass
|
||||
|
||||
@pytest.fixture
|
||||
def fix(self):
|
||||
return 1
|
||||
|
||||
@staticmethod
|
||||
def test_fix(fix):
|
||||
assert fix == 1
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
if sys.version_info < (2, 7):
|
||||
@@ -162,8 +172,8 @@ class TestClass(object):
|
||||
])
|
||||
else:
|
||||
result.stdout.fnmatch_lines([
|
||||
"*collected 1 item*",
|
||||
"*1 passed in*",
|
||||
"*collected 2 items*",
|
||||
"*2 passed in*",
|
||||
])
|
||||
|
||||
def test_setup_teardown_class_as_classmethod(self, testdir):
|
||||
|
||||
@@ -29,10 +29,16 @@ def test_getfuncargnames():
|
||||
def f(self, arg1, arg2="hello"):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def static(arg1, arg2):
|
||||
pass
|
||||
|
||||
assert fixtures.getfuncargnames(A().f) == ('arg1',)
|
||||
if sys.version_info < (3, 0):
|
||||
assert fixtures.getfuncargnames(A.f) == ('arg1',)
|
||||
|
||||
assert fixtures.getfuncargnames(A.static, cls=A) == ('arg1', 'arg2')
|
||||
|
||||
|
||||
class TestFillFixtures(object):
|
||||
def test_fillfuncargs_exposed(self):
|
||||
|
||||
@@ -135,3 +135,24 @@ def test_verbose_include_private_fixtures_and_loc(testdir):
|
||||
'arg3 -- test_verbose_include_private_fixtures_and_loc.py:3',
|
||||
' arg3 from testmodule',
|
||||
])
|
||||
|
||||
|
||||
def test_doctest_items(testdir):
|
||||
testdir.makepyfile('''
|
||||
def foo():
|
||||
"""
|
||||
>>> 1 + 1
|
||||
2
|
||||
"""
|
||||
''')
|
||||
testdir.maketxtfile('''
|
||||
>>> 1 + 1
|
||||
2
|
||||
''')
|
||||
result = testdir.runpytest("--fixtures-per-test", "--doctest-modules",
|
||||
"--doctest-glob=*.txt", "-v")
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
'*collected 2 items*',
|
||||
])
|
||||
|
||||
@@ -82,7 +82,7 @@ class TestArgComplete(object):
|
||||
from _pytest._argcomplete import FastFilesCompleter
|
||||
ffc = FastFilesCompleter()
|
||||
fc = FilesCompleter()
|
||||
for x in '/ /d /data qqq'.split():
|
||||
for x in ['/', '/d', '/data', 'qqq', '']:
|
||||
assert equal_with_bash(x, ffc, fc, out=py.std.sys.stdout)
|
||||
|
||||
@pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
|
||||
|
||||
@@ -1140,6 +1140,23 @@ def test_error_attribute_issue555(testdir):
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not sys.platform.startswith('win') and sys.version_info[:2] >= (3, 6),
|
||||
reason='only py3.6+ on windows')
|
||||
def test_py36_windowsconsoleio_workaround_non_standard_streams():
|
||||
"""
|
||||
Ensure _py36_windowsconsoleio_workaround function works with objects that
|
||||
do not implement the full ``io``-based stream protocol, for example execnet channels (#2666).
|
||||
"""
|
||||
from _pytest.capture import _py36_windowsconsoleio_workaround
|
||||
|
||||
class DummyStream:
|
||||
def write(self, s):
|
||||
pass
|
||||
|
||||
stream = DummyStream()
|
||||
_py36_windowsconsoleio_workaround(stream)
|
||||
|
||||
|
||||
def test_dontreadfrominput_has_encoding(testdir):
|
||||
testdir.makepyfile("""
|
||||
import sys
|
||||
|
||||
@@ -2,7 +2,8 @@ from __future__ import absolute_import, division, print_function
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from _pytest.compat import is_generator, get_real_func
|
||||
from _pytest.compat import is_generator, get_real_func, safe_getattr
|
||||
from _pytest.outcomes import OutcomeException
|
||||
|
||||
|
||||
def test_is_generator():
|
||||
@@ -74,3 +75,27 @@ def test_is_generator_async_syntax(testdir):
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(['*1 passed*'])
|
||||
|
||||
|
||||
class ErrorsHelper(object):
|
||||
@property
|
||||
def raise_exception(self):
|
||||
raise Exception('exception should be catched')
|
||||
|
||||
@property
|
||||
def raise_fail(self):
|
||||
pytest.fail('fail should be catched')
|
||||
|
||||
|
||||
def test_helper_failures():
|
||||
helper = ErrorsHelper()
|
||||
with pytest.raises(Exception):
|
||||
helper.raise_exception
|
||||
with pytest.raises(OutcomeException):
|
||||
helper.raise_fail
|
||||
|
||||
|
||||
def test_safe_getattr():
|
||||
helper = ErrorsHelper()
|
||||
assert safe_getattr(helper, 'raise_exception', 'default') == 'default'
|
||||
assert safe_getattr(helper, 'raise_fail', 'default') == 'default'
|
||||
|
||||
@@ -3,7 +3,7 @@ import py
|
||||
import pytest
|
||||
|
||||
import _pytest._code
|
||||
from _pytest.config import getcfg, get_common_ancestor, determine_setup
|
||||
from _pytest.config import getcfg, get_common_ancestor, determine_setup, _iter_rewritable_modules
|
||||
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||
|
||||
|
||||
@@ -308,6 +308,16 @@ class TestConfigAPI(object):
|
||||
config = testdir.parseconfig('--confcutdir', testdir.tmpdir.join('dir').ensure(dir=1))
|
||||
assert config.getoption('confcutdir') == str(testdir.tmpdir.join('dir'))
|
||||
|
||||
@pytest.mark.parametrize('names, expected', [
|
||||
(['bar.py'], ['bar']),
|
||||
(['foo', 'bar.py'], []),
|
||||
(['foo', 'bar.pyc'], []),
|
||||
(['foo', '__init__.py'], ['foo']),
|
||||
(['foo', 'bar', '__init__.py'], []),
|
||||
])
|
||||
def test_iter_rewritable_modules(self, names, expected):
|
||||
assert list(_iter_rewritable_modules(['/'.join(names)])) == expected
|
||||
|
||||
|
||||
class TestConfigFromdictargs(object):
|
||||
def test_basic_behavior(self):
|
||||
|
||||
@@ -812,3 +812,15 @@ def test_legacy_transfer():
|
||||
assert fake_method.fun
|
||||
# pristine marks dont transfer
|
||||
assert fake_method.pytestmark == [pytest.mark.fun.mark]
|
||||
|
||||
|
||||
class TestMarkDecorator(object):
|
||||
|
||||
@pytest.mark.parametrize('lhs, rhs, expected', [
|
||||
(pytest.mark.foo(), pytest.mark.foo(), True),
|
||||
(pytest.mark.foo(), pytest.mark.bar(), False),
|
||||
(pytest.mark.foo(), 'bar', False),
|
||||
('foo', pytest.mark.bar(), False)
|
||||
])
|
||||
def test__eq__(self, lhs, rhs, expected):
|
||||
assert (lhs == rhs) == expected
|
||||
|
||||
@@ -214,6 +214,16 @@ class TestTerminal(object):
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(['collected 1 item'])
|
||||
|
||||
def test_rewrite(self, testdir, monkeypatch):
|
||||
config = testdir.parseconfig()
|
||||
f = py.io.TextIO()
|
||||
monkeypatch.setattr(f, 'isatty', lambda *args: True)
|
||||
tr = TerminalReporter(config, f)
|
||||
tr.writer.fullwidth = 10
|
||||
tr.write('hello')
|
||||
tr.rewrite('hey', erase=True)
|
||||
assert f.getvalue() == 'hello' + '\r' + 'hey' + (7 * ' ')
|
||||
|
||||
|
||||
class TestCollectonly(object):
|
||||
def test_collectonly_basic(self, testdir):
|
||||
|
||||
17
tox.ini
17
tox.ini
@@ -12,10 +12,10 @@ envlist =
|
||||
py36
|
||||
py37
|
||||
pypy
|
||||
{py27,py35}-{pexpect,xdist,trial,numpy}
|
||||
{py27,py36}-{pexpect,xdist,trial,numpy}
|
||||
py27-nobyte
|
||||
doctesting
|
||||
freeze
|
||||
py35-freeze
|
||||
docs
|
||||
|
||||
[testenv]
|
||||
@@ -37,7 +37,6 @@ deps =
|
||||
|
||||
[testenv:py27-subprocess]
|
||||
changedir = .
|
||||
basepython = python2.7
|
||||
deps =
|
||||
pytest-xdist>=1.13
|
||||
mock
|
||||
@@ -68,7 +67,7 @@ deps =
|
||||
commands =
|
||||
pytest -n1 -rfsxX {posargs:testing}
|
||||
|
||||
[testenv:py35-xdist]
|
||||
[testenv:py36-xdist]
|
||||
deps = {[testenv:py27-xdist]deps}
|
||||
commands =
|
||||
pytest -n3 -rfsxX {posargs:testing}
|
||||
@@ -80,7 +79,7 @@ deps = pexpect
|
||||
commands =
|
||||
pytest -rfsxX test_pdb.py test_terminal.py test_unittest.py
|
||||
|
||||
[testenv:py35-pexpect]
|
||||
[testenv:py36-pexpect]
|
||||
changedir = testing
|
||||
platform = linux|darwin
|
||||
deps = {[testenv:py27-pexpect]deps}
|
||||
@@ -102,7 +101,7 @@ deps = twisted
|
||||
commands =
|
||||
pytest -ra {posargs:testing/test_unittest.py}
|
||||
|
||||
[testenv:py35-trial]
|
||||
[testenv:py36-trial]
|
||||
deps = {[testenv:py27-trial]deps}
|
||||
commands =
|
||||
pytest -ra {posargs:testing/test_unittest.py}
|
||||
@@ -112,7 +111,7 @@ deps=numpy
|
||||
commands=
|
||||
pytest -rfsxX {posargs:testing/python/approx.py}
|
||||
|
||||
[testenv:py35-numpy]
|
||||
[testenv:py36-numpy]
|
||||
deps=numpy
|
||||
commands=
|
||||
pytest -rfsxX {posargs:testing/python/approx.py}
|
||||
@@ -169,7 +168,7 @@ changedir = testing
|
||||
commands =
|
||||
{envpython} {envbindir}/py.test-jython -rfsxX {posargs}
|
||||
|
||||
[testenv:freeze]
|
||||
[testenv:py35-freeze]
|
||||
changedir = testing/freeze
|
||||
deps = pyinstaller
|
||||
commands =
|
||||
@@ -180,7 +179,6 @@ commands =
|
||||
[testenv:coveralls]
|
||||
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH COVERALLS_REPO_TOKEN
|
||||
usedevelop = True
|
||||
basepython = python3.5
|
||||
changedir = .
|
||||
deps =
|
||||
{[testenv]deps}
|
||||
@@ -200,6 +198,7 @@ python_files = test_*.py *_test.py testing/*/*.py
|
||||
python_classes = Test Acceptance
|
||||
python_functions = test
|
||||
norecursedirs = .tox ja .hg cx_freeze_source
|
||||
xfail_strict=true
|
||||
filterwarnings =
|
||||
error
|
||||
# produced by path.local
|
||||
|
||||
Reference in New Issue
Block a user