NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI, #25 most downloaded on PyPI
pytest: simple powerful testing with Python
Latest stable
9.2.0
Last release 25 days ago
27 Oct 2026
Ships fairly regularly
a new release about every 3 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
1 version withdrawn
withdrawn after publishing
16 years old
193 releases · first in 2010
Drag across the ruler to compare, or tap a release to open it.
Note: pytest was not able to provide a deprecation period for this change.
#7259 : The Node.reportinfo() function first return value type has been expanded from py.path.local | str to os.PathLike[str] | str .
Most plugins which refer to reportinfo() only define it as part of a custom pytest.Item implementation. Since py.path.local is an os.PathLike[str] , these plugins are unaffected.
Plugins and users which call reportinfo() , use the first return value and interact with it as a py.path.local , would need to adjust by calling py.path.local(fspath) . Although preferably, avoid the legacy py.path.local and use pathlib.Path , or use item.location or item.path , instead.
Note: pytest was not able to provide a deprecation period for this change.
#8246 : --version now writes version information to stdout rather than stderr .
#8592 : The pytest_cmdline_preparse hook has been removed following its deprecation. See the deprecation note for more details.
#8733 : Drop a workaround for pyreadline that made it work with --pdb .
The workaround was introduced in #1281 in 2015, however since then pyreadline seems to have gone unmaintained , is generating warnings , and will stop working on Python 3.10.
#9061 : Using pytest.approx() in a boolean context now raises an error hinting at the proper usage.
It is apparently common for users to mistakenly use pytest.approx like this:
assert pytest . approx ( actual , expected )
While the correct usage is:
assert actual == pytest . approx ( expected )
The new error message helps catch those mistakes.
#9277 : The pytest.Instance collector type has been removed. Importing pytest.Instance or _pytest.python.Instance returns a dummy type and emits a deprecation warning. See The pytest.Instance collector for details.
#9308 : PytestRemovedIn7Warning deprecation warnings are now errors by default.
Following our plan to remove deprecated features with as little disruption as possible, all warnings of type PytestRemovedIn7Warning now generate errors instead of warning messages by default.
The affected features will be effectively removed in pytest 7.1 , so please consult the Deprecations and Removals section in the docs for directions on how to update existing code.
In the pytest 7.0.X series, it is possible to change the errors back into warnings as a stopgap measure by adding this to your pytest.ini file:
[pytest] filterwarnings = ignore : :pytest.PytestRemovedIn7Warning
But this will stop working when pytest 7.1 is released.
If you have concerns about the removal of a specific feature, please add a comment to #9308 .
#7259 : py.path.local arguments for hooks have been deprecated. See the deprecation note for full details.
py.path.local arguments to Node constructors have been deprecated. See the deprecation note for full details.
Note
The name of the Node arguments and attributes (the new attribute being path ) is the opposite of the situation for hooks (the old argument being path ).
This is an unfortunate artifact due to historical reasons, which should be resolved in future versions as we slowly get rid of the py dependency (see #9283 for a longer discussion).
#7469 : Directly constructing the following classes is now deprecated:
_pytest.mark.structures.Mark
_pytest.mark.structures.MarkDecorator
_pytest.mark.structures.MarkGenerator
_pytest.python.Metafunc
_pytest.runner.CallInfo
_pytest._code.ExceptionInfo
_pytest.config.argparsing.Parser
_pytest.config.argparsing.OptionGroup
_pytest.pytester.HookRecorder
These constructors have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 8.
#8242 : Raising unittest.SkipTest to skip collection of tests during the pytest collection phase is deprecated. Use pytest.skip() instead.
Note: This deprecation only relates to using unittest.SkipTest during test collection. You are probably not doing that. Ordinary usage of unittest.SkipTest / unittest.TestCase.skipTest() / unittest.skip() in unittest test cases is fully supported.
Note
This deprecation has been reverted in pytest 7.1.0.
#8315 : Several behaviors of Parser.addoption are now scheduled for removal in pytest 8 (deprecated since pytest 2.4.0):
parser.addoption(..., help=".. %default ..") - use %(default)s instead.
parser.addoption(..., type="int/string/float/complex") - use type=int etc. instead.
#8447 : Defining a custom pytest node type which is both an Item and a Collector (e.g. File ) now issues a warning. It was never sanely supported and triggers hard to debug errors.
See the deprecation note for full details.
#8592 : pytest_cmdline_preparse has been officially deprecated. It will be removed in a future release. Use pytest_load_initial_conftests instead.
See the deprecation note for full details.
#8645 : pytest.warns(None) is now deprecated because many people used it to mean “this code does not emit warnings”, but it actually had the effect of checking that the code emits at least one warning of any type - like pytest.warns() or pytest.warns(Warning) .
#8948 : pytest.skip(msg=...) , pytest.fail(msg=...) and pytest.exit(msg=...) signatures now accept a reason argument instead of msg . Using msg still works, but is deprecated and will be removed in a future release.
This was changed for consistency with pytest.mark.skip and pytest.mark.xfail which both accept reason as an argument.
#8174 : The following changes have been made to types reachable through pytest.ExceptionInfo.traceback :
The path property of _pytest.code.Code returns Path instead of py.path.local .
The path property of _pytest.code.TracebackEntry returns Path instead of py.path.local .
There was no deprecation period for this change (sorry!).
#5196 : Tests are now ordered by definition order in more cases.
In a class hierarchy, tests from base classes are now consistently ordered before tests defined on their subclasses (reverse MRO order).
#7132 : Added two environment variables PYTEST_THEME and PYTEST_THEME_MODE to let the users customize the pygments theme used.
#7259 : Added cache.mkdir() , which is similar to the existing cache.makedir() , but returns a pathlib.Path instead of a legacy py.path.local .
Added a paths type to parser.addini() , as in parser.addini("mypaths", "my paths", type="paths") , which is similar to the existing pathlist , but returns a list of pathlib.Path instead of legacy py.path.local .
#7469 : The types of objects used in pytest’s API are now exported so they may be used in type annotations.
The newly-exported types are:
pytest.Config for Config .
pytest.Mark for marks .
pytest.MarkDecorator for mark decorators .
pytest.MarkGenerator for the pytest.mark singleton.
pytest.Metafunc for the metafunc argument to the pytest_generate_tests hook.
pytest.CallInfo for the CallInfo type passed to various hooks.
pytest.PytestPluginManager for PytestPluginManager .
pytest.ExceptionInfo for the ExceptionInfo type returned from pytest.raises() and passed to various hooks.
pytest.Parser for the Parser type passed to the pytest_addoption hook.
pytest.OptionGroup for the OptionGroup type returned from the parser.addgroup method.
pytest.HookRecorder for the HookRecorder type returned from Pytester .
pytest.RecordedHookCall for the RecordedHookCall type returned from HookRecorder .
pytest.RunResult for the RunResult type returned from Pytester .
pytest.LineMatcher for the LineMatcher type used in RunResult and others.
pytest.TestReport for the TestReport type used in various hooks.
pytest.CollectReport for the CollectReport type used in various hooks.
Constructing most of them directly is not supported; they are only meant for use in type annotations. Doing so will emit a deprecation warning, and may become a hard-error in pytest 8.0.
Subclassing them is also not supported. This is not currently enforced at runtime, but is detected by type-checkers such as mypy.
#7856 : –import-mode=importlib now works with features that depend on modules being on sys.modules , such as pickle and dataclasses .
#8144 : The following hooks now receive an additional pathlib.Path argument, equivalent to an existing py.path.local argument:
pytest_ignore_collect - The collection_path parameter (equivalent to existing path parameter).
pytest_collect_file - The file_path parameter (equivalent to existing path parameter).
pytest_pycollect_makemodule - The module_path parameter (equivalent to existing path parameter).
pytest_report_header - The start_path parameter (equivalent to existing startdir parameter).
pytest_report_collectionfinish - The start_path parameter (equivalent to existing startdir parameter).
Note
The name of the Node arguments and attributes (the new attribute being path ) is the opposite of the situation for hooks (the old argument being path ).
This is an unfortunate artifact due to historical reasons, which should be resolved in future versions as we slowly get rid of the py dependency (see #9283 for a longer discussion).
#8251 : Implement Node.path as a pathlib.Path . Both the old fspath and this new attribute gets set no matter whether path or fspath (deprecated) is passed to the constructor. It is a replacement for the fspath attribute (which represents the same path as py.path.local ). While fspath is not deprecated yet due to the ongoing migration of methods like reportinfo() , we expect to deprecate it in a future release.
Note
The name of the Node arguments and attributes (the new attribute being path ) is the opposite of the situation for hooks (the old argument being path ).
This is an unfortunate artifact due to historical reasons, which should be resolved in future versions as we slowly get rid of the py dependency (see #9283 for a longer discussion).
#8421 : pytest.approx() now works on Decimal within mappings/dicts and sequences/lists.
#8606 : pytest invocations with --fixtures-per-test and --fixtures have been enriched with:
Fixture location path printed with the fixture name.
First section of the fixture’s docstring printed under the fixture name.
Whole of fixture’s docstring printed under the fixture name using --verbose option.
#8761 : New pytest.version_tuple attribute, which makes it simpler for users to do something depending on the pytest version (such as declaring hooks which are introduced in later versions).
#8789 : Switch TOML parser from toml to tomli for TOML v1.0.0 support in pyproject.toml .
#8920 : Added pytest.Stash , a facility for plugins to store their data on Config and Node s in a type-safe and conflict-free manner. See Storing data on items across hook functions for details.
#8953 : RunResult method assert_outcomes() now accepts a warnings argument to assert the total number of warnings captured.
#8954 : --debug flag now accepts a str file to route debug logs into, remains defaulted to pytestdebug.log .
#9023 : Full diffs are now always shown for equality assertions of iterables when CI or BUILD_NUMBER is found in the environment, even when -v isn’t used.
#9113 : RunResult method assert_outcomes() now accepts a deselected argument to assert the total number of deselected tests.
#9114 : Added pythonpath setting that adds listed paths to sys.path for the duration of the test session. If you currently use the pytest-pythonpath or pytest-srcpaths plugins, you should be able to replace them with built-in pythonpath setting.
#7480 : A deprecation scheduled to be removed in a major version X (e.g. pytest 7, 8, 9, …) now uses warning category PytestRemovedInXWarning , a subclass of PytestDeprecationWarning , instead of PytestDeprecationWarning directly.
See Backwards Compatibility Policy for more details.
#7864 : Improved error messages when parsing warning filters.
Previously pytest would show an internal traceback, which besides being ugly sometimes would hide the cause of the problem (for example an ImportError while importing a specific warning type).
#8335 : Improved pytest.approx() assertion messages for sequences of numbers.
The assertion messages now dumps a table with the index and the error of each diff. Example:
assert [ 1 , 2 , 3 , 4 ] == pytest . approx ([ 1 , 3 , 3 , 5 ]) E assert comparison failed for 2 values : E Index | Obtained | Expected E 1 | 2 | 3 +- 3.0e-06 E 3 | 4 | 5 +- 5.0e-06
#8403 : By default, pytest will truncate long strings in assert errors so they don’t clutter the output too much, currently at 240 characters by default.
However, in some cases the longer output helps, or is even crucial, to diagnose a failure. Using -v will now increase the truncation threshold to 2400 characters, and -vv or higher will disable truncation entirely.
#8509 : Fixed issue where unittest.TestCase.setUpClass() is not called when a test has / in its name since pytest 6.2.0.
This refers to the path part in pytest node IDs, e.g. TestClass::test_it in the node ID tests/test_file.py::TestClass::test_it .
Now, instead of assuming that the test name does not contain / , it is assumed that test path does not contain :: . We plan to hopefully make both of these work in the future.
#8803 : It is now possible to add colors to custom log levels on cli log.
By using add_color_level from a pytest_configure hook, colors can be added:
logging_plugin = config . pluginmanager . get_plugin ( 'logging-plugin' ) logging_plugin . log_cli_handler . formatter . add_color_level ( logging . INFO , 'cyan' ) logging_plugin . log_cli_handler . formatter . add_color_level ( logging . SPAM , 'blue' )
See Customizing Colors for more information.
#8822 : When showing fixture paths in --fixtures or --fixtures-by-test , fixtures coming from pytest itself now display an elided path, rather than the full path to the file in the site-packages directory.
#8898 : Complex numbers are now treated like floats and integers when generating parameterization IDs.
#9062 : --stepwise-skip now implicitly enables --stepwise and can be used on its own.
#9205 : pytest.Cache.set() now preserves key order when saving dicts.
#7124 : Fixed an issue where main.py would raise an ImportError when --doctest-modules was provided.
#8061 : Fixed failing staticmethod test cases if they are inherited from a parent test class.
#8192 : testdir.makefile now silently accepts values which don’t start with . to maintain backward compatibility with older pytest versions.
pytester.makefile now issues a clearer error if the . is missing in the ext argument.
#8258 : Fixed issue where pytest’s faulthandler support would not dump traceback on crashes if the faulthandler module was already enabled during pytest startup (using python -X dev -m pytest for example).
#8317 : Fixed an issue where illegal directory characters derived from getpass.getuser() raised an OSError .
#8367 : Fix Class.from_parent so it forwards extra keyword arguments to the constructor.
#8377 : The test selection options pytest -k and pytest -m now support matching names containing forward slash ( / ) characters.
#8384 : The @pytest.mark.skip decorator now correctly handles its arguments. When the reason argument is accidentally given both positional and as a keyword (e.g. because it was confused with skipif ), a TypeError now occurs. Before, such tests were silently skipped, and the positional argument ignored. Additionally, reason is now documented correctly as positional or keyword (rather than keyword-only).
#8394 : Use private names for internal fixtures that handle classic setup/teardown so that they don’t show up with the default --fixtures invocation (but they still show up with --fixtures -v ).
#8456 : The required_plugins config option now works correctly when pre-releases of plugins are installed, rather than falsely claiming that those plugins aren’t installed at all.
#8464 : -c <config file> now also properly defines rootdir as the directory that contains <config file> .
#8503 : pytest.MonkeyPatch.syspath_prepend() no longer fails when setuptools is not installed. It now only calls pkg_resources.fixup_namespace_packages if pkg_resources was previously imported, because it is not needed otherwise.
#8548 : Introduce fix to handle precision width in log-cli-format in turn to fix output coloring for certain formats.
#8796 : Fixed internal error when skipping doctests.
#8983 : The test selection options pytest -k and pytest -m now support matching names containing backslash ( \ ) characters. Backslashes are treated literally, not as escape characters (the values being matched against are already escaped).
#8990 : Fix pytest -vv crashing with an internal exception AttributeError: 'str' object has no attribute 'relative_to' in some cases.
#9077 : Fixed confusing error message when request.fspath / request.path was accessed from a session-scoped fixture.
#9131 : Fixed the URL used by --pastebin to use bpa.st .
#9163 : The end line number and end column offset are now properly set for rewritten assert statements.
#9169 : Support for the files API from importlib.resources within rewritten files.
#9272 : The nose compatibility module-level fixtures setup() and teardown() are now only called once per module, instead of for each test function. They are now called even if object-level setup / teardown is defined.
#4320 : Improved docs for pytester.copy_example .
#5105 : Add automatically generated Pytest Plugin List . The list is updated on a periodic schedule.
#8337 : Recommend numpy.testing module on pytest.approx() documentation.
#8655 : Help text for --pdbcls more accurately reflects the option’s behavior.
#9210 : Remove incorrect docs about confcutdir being a configuration option: it can only be set through the --confcutdir command-line option.
#9242 : Upgrade readthedocs configuration to use a newer Ubuntu version https://blog.readthedocs.com/new-build-specification/`__ with better unicode support for PDF docs.
#9341 : Various methods commonly used for Working with non-python tests are now correctly documented in the reference docs. They were undocumented previously.
#8133 : Migrate to setuptools_scm 6.x to use SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST for more robust release tooling.
#8174 : The following changes have been made to internal pytest types/functions:
The _pytest.code.getfslineno() function returns Path instead of py.path.local .
The _pytest.python.path_matches_patterns() function takes Path instead of py.path.local .
The _pytest._code.Traceback.cut() function accepts any os.PathLike[str] , not just py.path.local .
#8248 : Internal Restructure: let python.PyObjMixin inherit from nodes.Node to carry over typing information.
#8432 : Improve error message when pytest.skip() is used at module level without passing allow_module_level=True .
#8818 : Ensure regendoc opts out of TOX_ENV cachedir selection to ensure independent example test runs.
#8913 : The private CallSpec2._arg2scopenum attribute has been removed after an internal refactoring.
#8967 : pytest_assertion_pass is no longer considered experimental and future changes to it will be considered more carefully.
#9202 : Add github action to upload coverage report to codecov instead of bash uploader.
#9225 : Changed the command used to create sdist and wheel artifacts: using the build package instead of setup.py.
#9351 : Correct minor typos in doc/en/example/special.rst.
Your coding agent can read these notes before it upgrades. Set up the MCP server →
\#8494: Python 3.10 is now supported.
\#8539: Fixed assertion rewriting on Python 3.10.
\#8414: pytest used to create directories under /tmp with world-readable permissions. This means that any user in the system was able to read informat
#8414: pytest used to create directories under /tmp with world-readable
permissions. This means that any user in the system was able to read
information written by tests in temporary directories (such as those created by
the tmp_path/tmpdir fixture). Now the directories are created with
private permissions.
pytest used silenty use a pre-existing /tmp/pytest-of-<username> directory,
even if owned by another user. This means another user could pre-create such a
directory and gain control of another user's temporary directory. Now such a
condition results in an error.
\#8152: Fixed "(<Skipped instance>)" being shown as a skip reason in the verbose test summary line when the reason is empty.
\#7678: Fixed bug where ImportPathMismatchError would be raised for files compiled in the host and loaded later from an UNC mounted path (Windows).
#7678: Fixed bug where ImportPathMismatchError would be raised for files compiled in
the host and loaded later from an UNC mounted path (Windows).
#8132: Fixed regression in approx: in 6.2.0 approx no longer raises
TypeError when dealing with non-numeric types, falling back to normal comparison.
Before 6.2.0, array types like tf.DeviceArray fell through to the scalar case,
and happened to compare correctly to a scalar if they had only one element.
After 6.2.0, these types began failing, because they inherited neither from
standard Python number hierarchy nor from numpy.ndarray.
approx now converts arguments to numpy.ndarray if they expose the array
protocol and are not scalars. This treats array-like objects like numpy arrays,
regardless of size.
\#7469: Directly constructing/calling the following classes/functions is now deprecated:
#7469: Directly constructing/calling the following classes/functions is now deprecated:
_pytest.cacheprovider.Cache_pytest.cacheprovider.Cache.for_config()_pytest.cacheprovider.Cache.clear_cache()_pytest.cacheprovider.Cache.cache_dir_from_config()_pytest.capture.CaptureFixture_pytest.fixtures.FixtureRequest_pytest.fixtures.SubRequest_pytest.logging.LogCaptureFixture_pytest.pytester.Pytester_pytest.pytester.Testdir_pytest.recwarn.WarningsRecorder_pytest.recwarn.WarningsChecker_pytest.tmpdir.TempPathFactory_pytest.tmpdir.TempdirFactoryThese have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 7.0.0.
#7530: The --strict command-line option has been deprecated, use --strict-markers instead.
We have plans to maybe in the future to reintroduce --strict and make it an encompassing flag for all strictness
related options (--strict-markers and --strict-config at the moment, more might be introduced in the future).
#7988: The @pytest.yield_fixture decorator/function is now deprecated. Use pytest.fixture instead.
yield_fixture has been an alias for fixture for a very long time, so can be search/replaced safely.
#5299: pytest now warns about unraisable exceptions and unhandled thread exceptions that occur in tests on Python>=3.8. See unraisable for more information.
#7425: New pytester fixture, which is identical to testdir but its methods return pathlib.Path when appropriate instead of py.path.local.
This is part of the movement to use pathlib.Path objects internally, in order to remove the dependency to py in the future.
Internally, the old Testdir <_pytest.pytester.Testdir> is now a thin wrapper around Pytester <_pytest.pytester.Pytester>, preserving the old interface.
#7695: A new hook was added, pytest_markeval_namespace which should return a dictionary. This dictionary will be used to augment the "global" variables available to evaluate skipif/xfail/xpass markers.
Pseudo example
conftest.py:
def pytest_markeval_namespace():
return {"color": "red"}
test_func.py:
@pytest.mark.skipif("color == 'blue'", reason="Color is not red")
def test_func():
assert False
#8006: It is now possible to construct a ~pytest.MonkeyPatch object directly as pytest.MonkeyPatch(),
in cases when the monkeypatch fixture cannot be used. Previously some users imported it
from the private _pytest.monkeypatch.MonkeyPatch namespace.
Additionally, MonkeyPatch.context <pytest.MonkeyPatch.context> is now a classmethod,
and can be used as with MonkeyPatch.context() as mp: .... This is the recommended way to use
MonkeyPatch directly, since unlike the monkeypatch fixture, an instance created directly
is not undo()-ed automatically.
#1265: Added an __str__ implementation to the ~pytest.pytester.LineMatcher class which is returned from pytester.run_pytest().stdout and similar. It returns the entire output, like the existing str() method.
#2044: Verbose mode now shows the reason that a test was skipped in the test's terminal line after the "SKIPPED", "XFAIL" or "XPASS".
#7469 The types of builtin pytest fixtures are now exported so they may be used in type annotations of test functions. The newly-exported types are:
pytest.FixtureRequest for the request fixture.pytest.Cache for the cache fixture.pytest.CaptureFixture[str] for the capfd and capsys fixtures.pytest.CaptureFixture[bytes] for the capfdbinary and capsysbinary fixtures.pytest.LogCaptureFixture for the caplog fixture.pytest.Pytester for the pytester fixture.pytest.Testdir for the testdir fixture.pytest.TempdirFactory for the tmpdir_factory fixture.pytest.TempPathFactory for the tmp_path_factory fixture.pytest.MonkeyPatch for the monkeypatch fixture.pytest.WarningsRecorder for the recwarn fixture.Constructing them is not supported (except for MonkeyPatch); they are only meant for use in type annotations. Doing so will emit a deprecation warning, and may become a hard-error in pytest 7.0.
Subclassing them is also not supported. This is not currently enforced at runtime, but is detected by type-checkers such as mypy.
#7527: When a comparison between namedtuple <collections.namedtuple> instances of the same type fails, pytest now shows the differing field names (possibly nested) instead of their indexes.
#7615: Node.warn <_pytest.nodes.Node.warn> now permits any subclass of Warning, not just PytestWarning <pytest.PytestWarning>.
#7701: Improved reporting when using --collected-only. It will now show the number of collected tests in the summary stats.
#7710: Use strict equality comparison for non-numeric types in pytest.approx instead of raising TypeError.
This was the undocumented behavior before 3.7, but is now officially a supported feature.
#7938: New --sw-skip argument which is a shorthand for --stepwise-skip.
#8023: Added 'node_modules' to default value for norecursedirs.
#8032: doClassCleanups <unittest.TestCase.doClassCleanups> (introduced in unittest in Python and 3.8) is now called appropriately.
--lf even though they contain tests that failed. Regressed in pytest 5.4.0.pytest --doctest-modules path/to/an/__init__.py.final class in the API reference._pytest.config.argparsing.Parser.addini() accepts explicit None and "string".\#7815: Improve deprecation warning message for pytest._fillfuncargs().
--lf even though they contain tests that failed. Regressed in pytest 5.4.0.pytest._fillfuncargs().\#7807: Fixed regression in pytest 6.1.0 causing incorrect rootdir to be determined in some non-trivial cases where parent directories have config fil
\#5585: As per our policy, the following features which have been deprecated in the 5.X series are now removed:
#5585: As per our policy, the following features which have been deprecated in the 5.X series are now removed:
funcargnames read-only property of FixtureRequest, Metafunc, and Function classes. Use fixturenames attribute.@pytest.fixture no longer supports positional arguments, pass all arguments by keyword instead.Node subclasses now raise an error, use from_parent instead.junit_family has changed to xunit2. If you require the old format, add junit_family=xunit1 to your configuration file.TerminalReporter no longer has a writer attribute. Plugin authors may use the public functions of the TerminalReporter instead of accessing the TerminalWriter object directly.--result-log option has been removed. Users are recommended to use the pytest-reportlog plugin instead.For more information consult Deprecations and Removals in the docs.
#6981: The pytest.collect module is deprecated: all its names can be imported from pytest directly.
#7097: The pytest._fillfuncargs function is deprecated. This function was kept
for backward compatibility with an older plugin.
It's functionality is not meant to be used directly, but if you must replace it, use function._request._fillfixtures() instead, though note this is not a public API and may break in the future.
#7210: The special -k '-expr' syntax to -k is deprecated. Use -k 'not expr'
instead.
The special -k 'expr:' syntax to -k is deprecated. Please open an issue
if you use this and want a replacement.
#7255: The pytest_warning_captured <_pytest.hookspec.pytest_warning_captured> hook is deprecated in favor of pytest_warning_recorded <_pytest.hookspec.pytest_warning_recorded>, and will be removed in a future version.
#7648: The gethookproxy() and isinitpath() methods of FSCollector and Package are deprecated;
use self.session.gethookproxy() and self.session.isinitpath() instead.
This should work on all pytest versions.
--durations-min command-line flag controls the minimal duration for inclusion in the slowest list of tests shown by --durations. Previously this was hard-coded to 0.005s.#6681: Internal pytest warnings issued during the early stages of initialization are now properly handled and can filtered through filterwarnings or --pythonwarnings/-W.
This also fixes a number of long standing issues: #2891, #7620, #7426.
#7572: When a plugin listed in required_plugins is missing or an unknown config key is used with --strict-config, a simple error message is now shown instead of a stacktrace.
#7685: Added two new attributes rootpath <_pytest.config.Config.rootpath> and inipath <_pytest.config.Config.inipath> to Config <_pytest.config.Config>. These attributes are pathlib.Path versions of the existing rootdir <_pytest.config.Config.rootdir> and inifile <_pytest.config.Config.inifile> attributes, and should be preferred over them when possible.
#7780: Public classes which are not designed to be inherited from are now marked @final.
Code which inherits from these classes will trigger a type-checking (e.g. mypy) error, but will still work in runtime.
Currently the final designation does not appear in the API Reference but hopefully will in the future.
#1953: Fixed error when overwriting a parametrized fixture, while also reusing the super fixture value.
# conftest.py
import pytest
@pytest.fixture(params=[1, 2])
def foo(request):
return request.param
# test_foo.py
import pytest
@pytest.fixture
def foo(foo):
return foo * 2
#4984: Fixed an internal error crash with IndexError: list index out of range when
collecting a module which starts with a decorated function, the decorator
raises, and assertion rewriting is enabled.
#7591: pylint shouldn't complain anymore about unimplemented abstract methods when inheriting from File <non-python tests>.
#7628: Fixed test collection when a full path without a drive letter was passed to pytest on Windows (for example \projects\tests\test.py instead of c:\projects\tests\pytest.py).
#7638: Fix handling of command-line options that appear as paths but trigger an OS-level syntax error on Windows, such as the options used internally by pytest-xdist.
#7742: Fixed INTERNALERROR when accessing locals / globals with faulty exec.
junitxml plugin has rewritten to use xml.etree.ElementTree.
The order of attributes in XML elements might differ. Some unneeded escaping is
no longer performed.more-itertools package has been removed.__class__,
__delattr__ and __new__) without consulting the python_classes and
python_functions configuration options and without passing them to plugins
using the pytest_pycollect_makeitem <_pytest.hookspec.pytest_pycollect_makeitem> hook.\#7148: Fixed --log-cli potentially causing unrelated print output to be swallowed.
--log-cli potentially causing unrelated print output to be swallowed.caplog.set_level is called more than once.--tb=line for example).\#7394: Passing an empty help value to Parser.add_option is now accepted instead of crashing when running pytest --help. Passing None raises a more in
help value to Parser.add_option is now accepted instead of crashing when running pytest --help.
Passing None raises a more informative TypeError.not-callable lint on pytest.mark.parametrize() and the other builtin marks:
skip, skipif, xfail, usefixtures, filterwarnings.TestReport.longreprtext (such as pytest-html) when TestReport.longrepr is not a string.caplog.set_level().The following breaking changes were made:
(Please see the full set of changes for this release also in the 6.0.0rc1 notes below)
#5584: PytestDeprecationWarning are now errors by default.
Following our plan to remove deprecated features with as little disruption as
possible, all warnings of type PytestDeprecationWarning now generate errors
instead of warning messages.
The affected features will be effectively removed in pytest 6.1, so please consult the Deprecations and Removals section in the docs for directions on how to update existing code.
In the pytest 6.0.X series, it is possible to change the errors back into warnings as a
stopgap measure by adding this to your pytest.ini file:
[pytest]
filterwarnings =
ignore::pytest.PytestDeprecationWarning
But this will stop working when pytest 6.1 is released.
If you have concerns about the removal of a specific feature, please add a comment to #5584.
#7472: The exec_() and is_true() methods of _pytest._code.Frame have been removed.
--log-file CLI option and log_file ini marker now create subdirectories if needed.match equals the obtained string but is not a regex match. In this case it is suggested to escape the regex.@pytest.mark.skip when --runxfail is used.capfd.TracebackEntry.__str__ which was changed by accident.usefixtures mark can apply fixtures to test.-q option used in getting started guide.package is no longer considered experimental.#1316: TestReport.longrepr is now always an instance of ReprExceptionInfo. Previously it was a str when a test failed with pytest.fail(..., pytrace=False).
#5965: symlinks are no longer resolved during collection and matching conftest.py files with test file paths.
Resolving symlinks for the current directory and during collection was introduced as a bugfix in 3.9.0, but it actually is a new feature which had unfortunate consequences in Windows and surprising results in other platforms.
The team decided to step back on resolving symlinks at all, planning to review this in the future with a more solid solution (see discussion in #6523 for details).
This might break test suites which made use of this feature; the fix is to create a symlink for the entire test tree, and not only to partial files/tress as it was possible previously.
#6505: Testdir.run().parseoutcomes() now always returns the parsed nouns in plural form.
Originally parseoutcomes() would always returns the nouns in plural form, but a change
meant to improve the terminal summary by using singular form single items (1 warning or 1 error)
caused an unintended regression by changing the keys returned by parseoutcomes().
Now the API guarantees to always return the plural form, so calls like this:
result = testdir.runpytest()
result.assert_outcomes(error=1)
Need to be changed to:
result = testdir.runpytest()
result.assert_outcomes(errors=1)
#6903: The os.dup() function is now assumed to exist. We are not aware of any
supported Python 3 implementations which do not provide it.
#7040: -k no longer matches against the names of the directories outside the test session root.
Also, pytest.Package.name is now just the name of the directory containing the package's
__init__.py file, instead of the full path. This is consistent with how the other nodes
are named, and also one of the reasons why -k would match against any directory containing
the test suite.
#7122: Expressions given to the -m and -k options are no longer evaluated using Python's eval.
The format supports or, and, not, parenthesis and general identifiers to match against.
Python constants, keywords or other operators are no longer evaluated differently.
#7135: Pytest now uses its own TerminalWriter class instead of using the one from the py library.
Plugins generally access this class through TerminalReporter.writer, TerminalReporter.write()
(and similar methods), or _pytest.config.create_terminal_writer().
The following breaking changes were made:
write() method and others) no longer flush implicitly; the flushing behavior
of the underlying file is respected. To flush explicitly (for example, if you
want output to be shown before an end-of-line is printed), use write(flush=True) or
terminal_writer.flush().bytes was removed.reline method and chars_on_current_line property were removed.stringio and encoding arguments was removed.#7224: The item.catch_log_handler and item.catch_log_handlers attributes, set by the logging plugin and never meant to be public , are no longer available.
The deprecated --no-print-logs option is removed. Use --show-capture instead.
#7226: Removed the unused args parameter from pytest.Function.__init__.
#7418: Removed the pytest_doctest_prepare_content hook specification. This hook hasn't been triggered by pytest for at least 10 years.
#7438: Some changes were made to the internal _pytest._code.source, listed here
for the benefit of plugin authors who may be using it:
deindent argument to Source() has been removed, now it is always true.Source() has been removed.Source with an str has been removed.Source.isparseable() and Source.putaround() have been removed.Source.compile() and function _pytest._code.compile() have
been removed; use plain compile() instead._pytest._code.source.getsource() has been removed; use
Source() directly instead.#7210: The special -k '-expr' syntax to -k is deprecated. Use -k 'not expr'
instead.
The special -k 'expr:' syntax to -k is deprecated. Please open an issue
if you use this and want a replacement.
#4049: pytest_warning_captured is deprecated in favor of the pytest_warning_recorded hook.
#1556: pytest now supports pyproject.toml files for configuration.
The configuration options is similar to the one available in other formats, but must be defined
in a [tool.pytest.ini_options] table to be picked up by pytest:
# pyproject.toml
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests",
"integration",
]
More information can be found in the docs.
#3342: pytest now includes inline type annotations and exposes them to user programs. Most of the user-facing API is covered, as well as internal code.
If you are running a type checker such as mypy on your tests, you may start noticing type errors indicating incorrect usage. If you run into an error that you believe to be incorrect, please let us know in an issue.
The types were developed against mypy version 0.780. Versions before 0.750 are known not to work. We recommend using the latest version. Other type checkers may work as well, but they are not officially verified to work by pytest yet.
#4049: Introduced a new hook named pytest_warning_recorded to convey information about warnings captured by the internal pytest warnings plugin.
This hook is meant to replace pytest_warning_captured, which is deprecated and will be removed in a future release.
#6471: New command-line flags:
#6856: A warning is now shown when an unknown key is read from a config INI file.
The --strict-config flag has been added to treat these warnings as errors.
#6906: Added --code-highlight command line option to enable/disable code highlighting in terminal output.
#7245: New --import-mode=importlib option that uses importlib to import test modules.
Traditionally pytest used __import__ while changing sys.path to import test modules (which
also changes sys.modules as a side-effect), which works but has a number of drawbacks, like requiring test modules
that don't live in packages to have unique names (as they need to reside under a unique name in sys.modules).
--import-mode=importlib uses more fine grained import mechanisms from importlib which don't
require pytest to change sys.path or sys.modules at all, eliminating much of the drawbacks
of the previous mode.
We intend to make --import-mode=importlib the default in future versions, so users are encouraged
to try the new mode and provide feedback (both positive or negative) in issue #7245.
You can read more about this option in the documentation.
#7305: New required_plugins configuration option allows the user to specify a list of plugins, including version information, that are required for pytest to run. An error is raised if any required plugins are not found when running pytest.
#4375: The pytest command now suppresses the BrokenPipeError error message that
is printed to stderr when the output of pytest is piped and and the pipe is
closed by the piped-to program (common examples are less and head).
#4391: Improved precision of test durations measurement. CallInfo items now have a new <CallInfo>.duration attribute, created using time.perf_counter(). This attribute is used to fill the <TestReport>.duration attribute, which is more accurate than the previous <CallInfo>.stop - <CallInfo>.start (as these are based on time.time()).
#4675: Rich comparison for dataclasses and attrs-classes is now recursive.
#6285: Exposed the pytest.FixtureLookupError exception which is raised by request.getfixturevalue() (where request is a FixtureRequest fixture) when a fixture with the given name cannot be returned.
#6433: If an error is encountered while formatting the message in a logging call, for
example logging.warning("oh no!: %s: %s", "first") (a second argument is
missing), pytest now propagates the error, likely causing the test to fail.
Previously, such a mistake would cause an error to be printed to stderr, which is not displayed by default for passing tests. This change makes the mistake visible during testing.
You may supress this behavior temporarily or permanently by setting
logging.raiseExceptions = False.
#6817: Explicit new-lines in help texts of command-line options are preserved, allowing plugins better control of the help displayed to users.
#6940: When using the --duration option, the terminal message output is now more precise about the number and duration of hidden items.
#6991: Collected files are displayed after any reports from hooks, e.g. the status from --lf.
#7091: When fd capturing is used, through --capture=fd or the capfd and
capfdbinary fixtures, and the file descriptor (0, 1, 2) cannot be
duplicated, FD capturing is still performed. Previously, direct writes to the
file descriptors would fail or be lost in this case.
#7119: Exit with an error if the --basetemp argument is empty, is the current working directory or is one of the parent directories.
This is done to protect against accidental data loss, as any directory passed to this argument is cleared.
#7128: pytest --version now displays just the pytest version, while pytest --version --version displays more verbose information including plugins. This is more consistent with how other tools show --version.
#7133: caplog.set_level() <_pytest.logging.LogCaptureFixture.set_level> will now override any log_level set via the CLI or configuration file.
#7159: caplog.set_level() <_pytest.logging.LogCaptureFixture.set_level> and caplog.at_level() <_pytest.logging.LogCaptureFixture.at_level> no longer affect the level of logs that are shown in the Captured log report report section.
#7348: Improve recursive diff report for comparison asserts on dataclasses / attrs.
#7385: --junitxml now includes the exception cause in the message XML attribute for failures during setup and teardown.
Previously:
<error message="test setup failure">
Now:
<error message="failed on setup with "ValueError: Some error during setup"">
#1120: Fix issue where directories from tmpdir are not removed properly when multiple instances of pytest are running in parallel.
#4583: Prevent crashing and provide a user-friendly error when a marker expression (-m) invoking of eval raises any exception.
#4677: The path shown in the summary report for SKIPPED tests is now always relative. Previously it was sometimes absolute.
#5456: Fix a possible race condition when trying to remove lock files used to control access to folders created by tmp_path and tmpdir.
#6240: Fixes an issue where logging during collection step caused duplication of log messages to stderr.
#6428: Paths appearing in error messages are now correct in case the current working directory has changed since the start of the session.
#6755: Support deleting paths longer than 260 characters on windows created inside tmpdir.
#6871: Fix crash with captured output when using capsysbinary.
#6909: Revert the change introduced by #6330, which required all arguments to @pytest.mark.parametrize to be explicitly defined in the function signature.
The intention of the original change was to remove what was expected to be an unintended/surprising behavior, but it turns out many people relied on it, so the restriction has been reverted.
#6910: Fix crash when plugins return an unknown stats while using the --reportlog option.
#6924: Ensure a unittest.IsolatedAsyncioTestCase is actually awaited.
#6925: Fix TerminalRepr instances to be hashable again.
#6947: Fix regression where functions registered with unittest.TestCase.addCleanup were not being called on test failures.
#6951: Allow users to still set the deprecated TerminalReporter.writer attribute.
#6956: Prevent pytest from printing ConftestImportFailure traceback to stdout.
#6991: Fix regressions with --lf filtering too much since pytest 5.4.
#6992: Revert "tmpdir: clean up indirection via config for factories" #6767 as it breaks pytest-xdist.
#7061: When a yielding fixture fails to yield a value, report a test setup error instead of crashing.
#7076: The path of file skipped by @pytest.mark.skip in the SKIPPED report is now relative to invocation directory. Previously it was relative to root directory.
#7110: Fixed regression: asyncbase.TestCase tests are executed correctly again.
#7126: --setup-show now doesn't raise an error when a bytes value is used as a parametrize
parameter when Python is called with the -bb flag.
#7143: Fix pytest.File.from_parent so it forwards extra keyword arguments to the constructor.
#7145: Classes with broken __getattribute__ methods are displayed correctly during failures.
#7150: Prevent hiding the underlying exception when ConfTestImportFailure is raised.
#7180: Fix _is_setup_py for files encoded differently than locale.
#7215: Fix regression where running with --pdb would call unittest.TestCase.tearDown for skipped tests.
#7253: When using pytest.fixture on a function directly, as in pytest.fixture(func),
if the autouse or params arguments are also passed, the function is no longer
ignored, but is marked as a fixture.
#7360: Fix possibly incorrect evaluation of string expressions passed to pytest.mark.skipif and pytest.mark.xfail,
in rare circumstances where the exact same string is used but refers to different global values.
#7383: Fixed exception causes all over the codebase, i.e. use raise new_exception from old_exception when wrapping an exception.
--strict and --strict-markers and the preference for the latter one.originalname attribute of _pytest.python.Function now defaults to name if not
provided explicitly, and is always set.wcwidth package has been removed.py.iniconfig with iniconfig.src/_pytest/config/__init__.py now uses the warnings module to report warnings instead of sys.stderr.write.pytest-xdist.py>=1.8.2 is now required.The following breaking changes were made:
#1316: TestReport.longrepr is now always an instance of ReprExceptionInfo. Previously it was a str when a test failed with pytest.fail(..., pytrace=False).
#5965: symlinks are no longer resolved during collection and matching conftest.py files with test file paths.
Resolving symlinks for the current directory and during collection was introduced as a bugfix in 3.9.0, but it actually is a new feature which had unfortunate consequences in Windows and surprising results in other platforms.
The team decided to step back on resolving symlinks at all, planning to review this in the future with a more solid solution (see discussion in #6523 for details).
This might break test suites which made use of this feature; the fix is to create a symlink for the entire test tree, and not only to partial files/tress as it was possible previously.
#6505: Testdir.run().parseoutcomes() now always returns the parsed nouns in plural form.
Originally parseoutcomes() would always returns the nouns in plural form, but a change
meant to improve the terminal summary by using singular form single items (1 warning or 1 error)
caused an unintended regression by changing the keys returned by parseoutcomes().
Now the API guarantees to always return the plural form, so calls like this:
result = testdir.runpytest()
result.assert_outcomes(error=1)
Need to be changed to:
result = testdir.runpytest()
result.assert_outcomes(errors=1)
#6903: The os.dup() function is now assumed to exist. We are not aware of any
supported Python 3 implementations which do not provide it.
#7040: -k no longer matches against the names of the directories outside the test session root.
Also, pytest.Package.name is now just the name of the directory containing the package's
__init__.py file, instead of the full path. This is consistent with how the other nodes
are named, and also one of the reasons why -k would match against any directory containing
the test suite.
#7122: Expressions given to the -m and -k options are no longer evaluated using Python's eval.
The format supports or, and, not, parenthesis and general identifiers to match against.
Python constants, keywords or other operators are no longer evaluated differently.
#7135: Pytest now uses its own TerminalWriter class instead of using the one from the py library.
Plugins generally access this class through TerminalReporter.writer, TerminalReporter.write()
(and similar methods), or _pytest.config.create_terminal_writer().
The following breaking changes were made:
write() method and others) no longer flush implicitly; the flushing behavior
of the underlying file is respected. To flush explicitly (for example, if you
want output to be shown before an end-of-line is printed), use write(flush=True) or
terminal_writer.flush().bytes was removed.reline method and chars_on_current_line property were removed.stringio and encoding arguments was removed.#7224: The item.catch_log_handler and item.catch_log_handlers attributes, set by the logging plugin and never meant to be public , are no longer available.
The deprecated --no-print-logs option is removed. Use --show-capture instead.
#7226: Removed the unused args parameter from pytest.Function.__init__.
#7418: Removed the pytest_doctest_prepare_content hook specification. This hook hasn't been triggered by pytest for at least 10 years.
#7438: Some changes were made to the internal _pytest._code.source, listed here
for the benefit of plugin authors who may be using it:
deindent argument to Source() has been removed, now it is always true.Source() has been removed.Source with an str has been removed.Source.isparseable() and Source.putaround() have been removed.Source.compile() and function _pytest._code.compile() have
been removed; use plain compile() instead._pytest._code.source.getsource() has been removed; use
Source() directly instead.#7210: The special -k '-expr' syntax to -k is deprecated. Use -k 'not expr'
instead.
The special -k 'expr:' syntax to -k is deprecated. Please open an issue
if you use this and want a replacement.
#4049: pytest_warning_captured is deprecated in favor of the pytest_warning_recorded hook.
#1556: pytest now supports pyproject.toml files for configuration.
The configuration options is similar to the one available in other formats, but must be defined
in a [tool.pytest.ini_options] table to be picked up by pytest:
# pyproject.toml
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests",
"integration",
]
More information can be found in the docs.
#3342: pytest now includes inline type annotations and exposes them to user programs. Most of the user-facing API is covered, as well as internal code.
If you are running a type checker such as mypy on your tests, you may start noticing type errors indicating incorrect usage. If you run into an error that you believe to be incorrect, please let us know in an issue.
The types were developed against mypy version 0.780. Versions before 0.750 are known not to work. We recommend using the latest version. Other type checkers may work as well, but they are not officially verified to work by pytest yet.
#4049: Introduced a new hook named pytest_warning_recorded to convey information about warnings captured by the internal pytest warnings plugin.
This hook is meant to replace pytest_warning_captured, which is deprecated and will be removed in a future release.
#6471: New command-line flags:
#6856: A warning is now shown when an unknown key is read from a config INI file.
The --strict-config flag has been added to treat these warnings as errors.
#6906: Added --code-highlight command line option to enable/disable code highlighting in terminal output.
#7245: New --import-mode=importlib option that uses importlib to import test modules.
Traditionally pytest used __import__ while changing sys.path to import test modules (which
also changes sys.modules as a side-effect), which works but has a number of drawbacks, like requiring test modules
that don't live in packages to have unique names (as they need to reside under a unique name in sys.modules).
--import-mode=importlib uses more fine grained import mechanisms from importlib which don't
require pytest to change sys.path or sys.modules at all, eliminating much of the drawbacks
of the previous mode.
We intend to make --import-mode=importlib the default in future versions, so users are encouraged
to try the new mode and provide feedback (both positive or negative) in issue #7245.
You can read more about this option in the documentation.
#7305: New required_plugins configuration option allows the user to specify a list of plugins, including version information, that are required for pytest to run. An error is raised if any required plugins are not found when running pytest.
#4375: The pytest command now suppresses the BrokenPipeError error message that
is printed to stderr when the output of pytest is piped and and the pipe is
closed by the piped-to program (common examples are less and head).
#4391: Improved precision of test durations measurement. CallInfo items now have a new <CallInfo>.duration attribute, created using time.perf_counter(). This attribute is used to fill the <TestReport>.duration attribute, which is more accurate than the previous <CallInfo>.stop - <CallInfo>.start (as these are based on time.time()).
#4675: Rich comparison for dataclasses and attrs-classes is now recursive.
#6285: Exposed the pytest.FixtureLookupError exception which is raised by request.getfixturevalue() (where request is a FixtureRequest fixture) when a fixture with the given name cannot be returned.
#6433: If an error is encountered while formatting the message in a logging call, for
example logging.warning("oh no!: %s: %s", "first") (a second argument is
missing), pytest now propagates the error, likely causing the test to fail.
Previously, such a mistake would cause an error to be printed to stderr, which is not displayed by default for passing tests. This change makes the mistake visible during testing.
You may supress this behavior temporarily or permanently by setting
logging.raiseExceptions = False.
#6817: Explicit new-lines in help texts of command-line options are preserved, allowing plugins better control of the help displayed to users.
#6940: When using the --duration option, the terminal message output is now more precise about the number and duration of hidden items.
#6991: Collected files are displayed after any reports from hooks, e.g. the status from --lf.
#7091: When fd capturing is used, through --capture=fd or the capfd and
capfdbinary fixtures, and the file descriptor (0, 1, 2) cannot be
duplicated, FD capturing is still performed. Previously, direct writes to the
file descriptors would fail or be lost in this case.
#7119: Exit with an error if the --basetemp argument is empty, is the current working directory or is one of the parent directories.
This is done to protect against accidental data loss, as any directory passed to this argument is cleared.
#7128: pytest --version now displays just the pytest version, while pytest --version --version displays more verbose information including plugins. This is more consistent with how other tools show --version.
#7133: caplog.set_level() <_pytest.logging.LogCaptureFixture.set_level> will now override any log_level set via the CLI or configuration file.
#7159: caplog.set_level() <_pytest.logging.LogCaptureFixture.set_level> and caplog.at_level() <_pytest.logging.LogCaptureFixture.at_level> no longer affect the level of logs that are shown in the Captured log report report section.
#7348: Improve recursive diff report for comparison asserts on dataclasses / attrs.
#7385: --junitxml now includes the exception cause in the message XML attribute for failures during setup and teardown.
Previously:
<error message="test setup failure">
Now:
<error message="failed on setup with "ValueError: Some error during setup"">
#1120: Fix issue where directories from tmpdir are not removed properly when multiple instances of pytest are running in parallel.
#4583: Prevent crashing and provide a user-friendly error when a marker expression (-m) invoking of eval raises any exception.
#4677: The path shown in the summary report for SKIPPED tests is now always relative. Previously it was sometimes absolute.
#5456: Fix a possible race condition when trying to remove lock files used to control access to folders created by tmp_path and tmpdir.
#6240: Fixes an issue where logging during collection step caused duplication of log messages to stderr.
#6428: Paths appearing in error messages are now correct in case the current working directory has changed since the start of the session.
#6755: Support deleting paths longer than 260 characters on windows created inside tmpdir.
#6871: Fix crash with captured output when using capsysbinary.
#6909: Revert the change introduced by #6330, which required all arguments to @pytest.mark.parametrize to be explicitly defined in the function signature.
The intention of the original change was to remove what was expected to be an unintended/surprising behavior, but it turns out many people relied on it, so the restriction has been reverted.
#6910: Fix crash when plugins return an unknown stats while using the --reportlog option.
#6924: Ensure a unittest.IsolatedAsyncioTestCase is actually awaited.
#6925: Fix TerminalRepr instances to be hashable again.
#6947: Fix regression where functions registered with unittest.TestCase.addCleanup were not being called on test failures.
#6951: Allow users to still set the deprecated TerminalReporter.writer attribute.
#6956: Prevent pytest from printing ConftestImportFailure traceback to stdout.
#6991: Fix regressions with --lf filtering too much since pytest 5.4.
#6992: Revert "tmpdir: clean up indirection via config for factories" #6767 as it breaks pytest-xdist.
#7061: When a yielding fixture fails to yield a value, report a test setup error instead of crashing.
#7076: The path of file skipped by @pytest.mark.skip in the SKIPPED report is now relative to invocation directory. Previously it was relative to root directory.
#7110: Fixed regression: asyncbase.TestCase tests are executed correctly again.
#7126: --setup-show now doesn't raise an error when a bytes value is used as a parametrize
parameter when Python is called with the -bb flag.
#7143: Fix pytest.File.from_parent so it forwards extra keyword arguments to the constructor.
#7145: Classes with broken __getattribute__ methods are displayed correctly during failures.
#7150: Prevent hiding the underlying exception when ConfTestImportFailure is raised.
#7180: Fix _is_setup_py for files encoded differently than locale.
#7215: Fix regression where running with --pdb would call unittest.TestCase.tearDown for skipped tests.
#7253: When using pytest.fixture on a function directly, as in pytest.fixture(func),
if the autouse or params arguments are also passed, the function is no longer
ignored, but is marked as a fixture.
#7360: Fix possibly incorrect evaluation of string expressions passed to pytest.mark.skipif and pytest.mark.xfail,
in rare circumstances where the exact same string is used but refers to different global values.
#7383: Fixed exception causes all over the codebase, i.e. use raise new_exception from old_exception when wrapping an exception.
--strict and --strict-markers and the preference for the latter one.originalname attribute of _pytest.python.Function now defaults to name if not
provided explicitly, and is always set.wcwidth package has been removed.py.iniconfig with iniconfig.src/_pytest/config/__init__.py now uses the warnings module to report warnings instead of sys.stderr.write.pytest-xdist.py>=1.8.2 is now required.\#6428: Paths appearing in error messages are now correct in case the current working directory has changed since the start of the session.
ConfTestImportFailure is raised.--pdb would call the tearDown methods of unittest.TestCase
subclasses for skipped tests.\#6951: Allow users to still set the deprecated TerminalReporter.writer attribute.
unittest.IsolatedAsyncioTestCase is actually awaited.TestCase.addCleanup were not being called on test failures.TerminalReporter.writer attribute.asyncbase.TestCase tests are executed correctly again.File.from_constructor so it forwards extra keyword arguments to the constructor.__getattribute__ methods are displayed correctly during failures._is_setup_py for files encoded differently than locale.\#6909: Revert the change introduced by \#6330, which required all arguments to @pytest.mark.parametrize to be explicitly defined in the function sign
#6909: Revert the change introduced by #6330, which required all arguments to @pytest.mark.parametrize to be explicitly defined in the function signature.
The intention of the original change was to remove what was expected to be an unintended/surprising behavior, but it turns out many people relied on it, so the restriction has been reverted.
#6910: Fix crash when plugins return an unknown stats while using the --reportlog option.
\#6637: Removed the long-deprecated pytest_itemstart hook.
#6316: Matching of -k EXPRESSION to test names is now case-insensitive.
#6443: Plugins specified with -p are now loaded after internal plugins, which results in their hooks being called before the internal ones.
This makes the -p behavior consistent with PYTEST_PLUGINS.
#6637: Removed the long-deprecated pytest_itemstart hook.
This hook has been marked as deprecated and not been even called by pytest for over 10 years now.
#6673: Reversed / fix meaning of "+/-" in error diffs. "-" means that sth. expected is missing in the result and "+" means that there are unexpected extras in the result.
#6737: The cached_result attribute of FixtureDef is now set to None when
the result is unavailable, instead of being deleted.
If your plugin performs checks like hasattr(fixturedef, 'cached_result'),
for example in a pytest_fixture_post_finalizer hook implementation, replace
it with fixturedef.cached_result is not None. If you del the attribute,
set it to None instead.
#3238: Option --no-print-logs is deprecated and meant to be removed in a future release. If you use --no-print-logs, please try out --show-capture and
provide feedback.
--show-capture command-line option was added in pytest 3.5.0 and allows to specify how to
display captured output when tests fail: no, stdout, stderr, log or all (the default).
#571: Deprecate the unused/broken [pytest_collect_directory]{.title-ref} hook.
It was misaligned since the removal of the Directory collector in 2010
and incorrect/unusable as soon as collection was split from test execution.
#5975: Deprecate using direct constructors for Nodes.
Instead they are new constructed via Node.from_parent.
This transitional mechanism enables us to detangle the very intensely
entangled Node relationships by enforcing more controlled creation/configruation patterns.
As part of that session/config are already disallowed parameters and as we work on the details we might need disallow a few more as well.
Subclasses are expected to use [super().from_parent]{.title-ref} if they intend to expand the creation of [Nodes]{.title-ref}.
#6779: The TerminalReporter.writer attribute has been deprecated and should no longer be used. This
was inadvertently exposed as part of the public API of that plugin and ties it too much
with py.io.TerminalWriter.
--capture=tee-sys <capture-method>{.interpreted-text role="ref"} option to allow both live printing and capturing of test output.@pytest.mark.parametrize need to be explicitly declared in the function signature or via indirect.
Previously it was possible to omit an argument if a fixture with the same name existed, which was just an accident of implementation and was not meant to be a part of the API.short test summary <pytest.detailed_failed_tests_usage>{.interpreted-text role="ref"}. [-rN]{.title-ref} can be used to disable it (the old behavior).junit_logging{.interpreted-text role="confval"} option: log, out-err, and all.#1857: pytest.mark.parametrize accepts integers for ids again, converting it to strings.
#449: Use "yellow" main color with any XPASSED tests.
#4639: Revert "A warning is now issued when assertions are made for None".
The warning proved to be less useful than initially expected and had quite a few false positive cases.
#5686: tmpdir_factory.mktemp now fails when given absolute and non-normalized paths.
#5984: The pytest_warning_captured hook now receives a location parameter with the code location that generated the warning.
#6213: pytester: the testdir fixture respects environment settings from the monkeypatch fixture for inner runs.
#6247: --fulltrace is honored with collection errors.
#6384: Make [--showlocals]{.title-ref} work also with [--tb=short]{.title-ref}.
#6653: Add support for matching lines consecutively with LineMatcher <_pytest.pytester.LineMatcher>{.interpreted-text role="attr"}'s ~_pytest.pytester.LineMatcher.fnmatch_lines{.interpreted-text role="func"} and ~_pytest.pytester.LineMatcher.re_match_lines{.interpreted-text role="func"}.
#6658: Code is now highlighted in tracebacks when pygments is installed.
Users are encouraged to install pygments into their environment and provide feedback, because
the plan is to make pygments a regular dependency in the future.
#6795: Import usage error message with invalid [-o]{.title-ref} option.
#759: pytest.mark.parametrize supports iterators and generators for ids.
#310: Add support for calling [pytest.xfail()]{.title-ref} and [pytest.importorskip()]{.title-ref} with doctests.
#3823: --trace now works with unittests.
#4445: Fixed some warning reports produced by pytest to point to the correct location of the warning in the user's code.
#5301: Fix --last-failed to collect new tests from files with known failures.
#5928: Report PytestUnknownMarkWarning at the level of the user's code, not pytest's.
#5991: Fix interaction with --pdb and unittests: do not use unittest's TestCase.debug().
#6334: Fix summary entries appearing twice when f/F and s/S report chars were used at the same time in the -r command-line option (for example -rFf).
The upper case variants were never documented and the preferred form should be the lower case.
#6409: Fallback to green (instead of yellow) for non-last items without previous passes with colored terminal progress indicator.
#6454: [--disable-warnings]{.title-ref} is honored with [-ra]{.title-ref} and [-rA]{.title-ref}.
#6497: Fix bug in the comparison of request key with cached key in fixture.
A construct if key == cached_key: can fail either because == is explicitly disallowed, or for, e.g., NumPy arrays, where the result of a == b cannot generally be converted to [bool]{.title-ref}.
The implemented fix replaces [==]{.title-ref} with is.
#6557: Make capture output streams .write() method return the same return value from original streams.
#6566: Fix EncodedFile.writelines to call the underlying buffer's writelines method.
#6575: Fix internal crash when faulthandler starts initialized
(for example with PYTHONFAULTHANDLER=1 environment variable set) and faulthandler_timeout defined
in the configuration file.
#6597: Fix node ids which contain a parametrized empty-string variable.
#6646: Assertion rewriting hooks are (re)stored for the current item, which fixes them being still used after e.g. pytester's testdir.runpytest <_pytest.pytester.Testdir.runpytest>{.interpreted-text role="func"} etc.
#6660: pytest.exit() <_pytest.outcomes.exit>{.interpreted-text role="func"} is handled when emitted from the pytest_sessionfinish <_pytest.hookspec.pytest_sessionfinish>{.interpreted-text role="func"} hook. This includes quitting from a debugger.
#6752: When :pypytest.raises{.interpreted-text role="func"} is used as a function (as opposed to a context manager),
a [match]{.title-ref} keyword argument is now passed through to the tested function. Previously
it was swallowed and ignored (regression in pytest 5.1.0).
#6801: Do not display empty lines inbetween traceback for unexpected exceptions with doctests.
#6802: The testdir fixture <testdir>{.interpreted-text role="fixture"} works within doctests now.
parser module, deprecated in Python 3.9.\#6517: Fix regression in pytest 5.3.4 causing an INTERNALERROR due to a wrong assertion.
\#6496: Revert \#6436: unfortunately this change has caused a number of regressions in many suites, so the team decided to revert this change and make
\#2780: Captured output during teardown is shown with -rP.
-rP.pytest-xdist crash when dealing with exceptions raised in
subprocesses created by the multiprocessing module.testdir
results (regression in 5.3.0).\#4639: Revert \"A warning is now issued when assertions are made for None\".
#4639: Revert
"A warning is now issued when assertions are made for None".
The warning proved to be less useful than initially expected and had quite a few false positive cases.
.pytest_cache directory are kept with
--cache-clear, which only clears cached values now.editable
installs (pip install --editable).\#6231: Improve check for misspelling of pytest.mark.parametrize.
pytest.mark.parametrize.no_fnmatch_line when used after positive matching.property docstrings, as a workaround to bpo-17446.sys.last_traceback, sys.last_type and sys.last_value attributes by deleting them instead of setting them to None. This better matches the behaviour of the Python standard library.#6231 : Improve check for misspelling of pytest.mark.parametrize .
#6257 : Handle pytest.exit() being used via pytest_internalerror , e.g. when quitting pdb from post mortem.
#5914 : pytester: fix no_fnmatch_line() when used after positive matching.
#6082 : Fix line detection for doctest samples inside property docstrings, as a workaround to python/cpython#61648 .
#6254 : Fix compatibility with pytest-parallel (regression in pytest 5.3.0).
#6255 : Clear the sys.last_traceback , sys.last_type and sys.last_value attributes by deleting them instead of setting them to None . This better matches the behaviour of the Python standard library.
The plugin is meant to replace the --resultlog option, which is deprecated and meant to be removed in a future release. If you use --resultlog, please…
#6179: The
default value of junit_family option will change to xunit2 in
pytest 6.0, given that this is the version supported by default in
modern tools that manipulate this type of file.
In order to smooth the transition, pytest will issue a warning in
case the --junitxml option is given in the command line but
junit_family is not explicitly configured in pytest.ini.
For more information, see the docs.
#4488: The
pytest team has created the
pytest-reportlog
plugin, which provides a new --report-log=FILE option that writes
report logs into a file as the test session executes.
Each line of the report log contains a self contained JSON object corresponding to a testing event, such as a collection or a test result report. The file is guaranteed to be flushed after writing each line, so systems can read and process events in real-time.
The plugin is meant to replace the --resultlog option, which is
deprecated and meant to be removed in a future release. If you use
--resultlog, please try out pytest-reportlog and
provide feedback.
#4730: When
sys.pycache_prefix (Python 3.8+) is set, it will be used by pytest
to cache test files changed by the assertion rewriting mechanism.
This makes it easier to benefit of cached .pyc files even on file
systems without permissions.
#5515: Allow selective auto-indentation of multiline log messages.
Adds command line option --log-auto-indent, config option
log_auto_indent and support for per-entry configuration of
indentation behavior on calls to logging.log().
Alters the default for auto-indention from on to off. This
restores the older behavior that existed prior to v4.6.0. This
reversion to earlier behavior was done because it is better to
activate new features that may lead to broken tests explicitly
rather than implicitly.
#5914:
pytester learned two new functions,
no_fnmatch_line
and
no_re_match_line.
The functions are used to ensure the captured text does not match the given pattern.
The previous idiom was to use re.match:
assert re.match(pat, result.stdout.str()) is None
Or the in operator:
assert text in result.stdout.str()
But the new functions produce best output on failure.
#6057: Added
tolerances to complex values when printing pytest.approx.
For example, repr(pytest.approx(3+4j)) returns
(3+4j) ± 5e-06 ∠ ±180°. This is polar notation indicating a circle
around the expected value, with a radius of 5e-06. For approx
comparisons to return True, the actual value should fall within
this circle.
#6061: Added
the pluginmanager as an argument to pytest_addoption so that hooks
can be invoked when setting up command line options. This is useful
for having one plugin communicate things to another plugin, such as
default values or which set of command line options to add.
#5061: Use multiple colors with terminal summary statistics.
#5630: Quitting
from debuggers is now properly handled in doctest items.
#5924: Improved verbose diff output with sequences.
Before:
E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...]
E Right contains 3 more items, first extra item: ' '
E Full diff:
E - ['version', 'version_info', 'sys.version', 'sys.version_info']
E + ['version',
E + 'version_info',
E + 'sys.version',
E + 'sys.version_info',
E + ' ',
E + 'sys.version',
E + 'sys.version_info']
After:
E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...]
E Right contains 3 more items, first extra item: ' '
E Full diff:
E [
E 'version',
E 'version_info',
E 'sys.version',
E 'sys.version_info',
E + ' ',
E + 'sys.version',
E + 'sys.version_info',
E ]
#5936: Display
untruncated assertion message with -vv.
#5990: Fixed plurality mismatch in test summary (e.g. display "1 error" instead of "1 errors").
#6008:
Config.InvocationParams.args is now always a tuple to better
convey that it should be immutable and avoid
accidental modifications.
#6023:
pytest.main now returns a pytest.ExitCode instance now, except
for when custom exit codes are used (where it returns int
then still).
#6026: Align
prefixes in output of pytester's LineMatcher.
#6059: Collection errors are reported as errors (and not failures like before) in the terminal's short test summary.
#6069:
pytester.spawn does not skip/xfail tests on FreeBSD
anymore unconditionally.
#6097: The "[XXX%]" indicator in the test summary is now colored according to the final (new) multi-colored line's main color.
#6116: Added
--co as a synonym to --collect-only.
#6148:
atomicwrites is now only used on Windows, fixing a performance
regression with assertion rewriting on Unix.
#6152: Now
parametrization will use the __name__ attribute of any object for
the id, if present. Previously it would only use __name__ for
functions and classes.
#6176: Improved
failure reporting with pytester's Hookrecorder.assertoutcome.
#6181: The
reason for a stopped session, e.g. with --maxfail / -x, now gets
reported in the test summary.
#6206: Improved
cache.set robustness and performance.
#2049: Fixed
--setup-plan showing inaccurate information about
fixture lifetimes.
#2548: Fixed line offset mismatch of skipped tests in terminal summary.
#6039: The
PytestDoctestRunner is now properly invalidated when unconfiguring
the doctest plugin.
This is important when used with pytester's runpytest_inprocess.
#6047:
BaseExceptions are now handled in saferepr, which includes
pytest.fail.Exception etc.
#6074:
pytester: fixed order of arguments in rm_rf warning when cleaning
up temporary directories, and do not emit warnings for errors with
os.open.
#6189: Fixed
result of getmodpath method.
RunResult from pytester now displays the mnemonic of the ret
attribute when it is a valid pytest.ExitCode value.\#6194: Fix incorrect discovery of non-test __init__.py files.
\#5830: The first test in a package (__init__.py) marked with @pytest.mark.skip is now correctly skipped.
\#5206: Fix --nf to not forget about known nodeids with partial test selection.
--nf to not forget about known nodeids with partial
test selection.KeyboardInterrupt during --setup-show.FileNotFoundError exceptions when trying to remove old
temporary directories, for instance when multiple processes try to
remove the same directory (common with pytest-xdist for example).\#5902: Fix warnings about deprecated cmp attribute in attrs>=19.2.
cmp attribute in attrs>=19.2.\#1682: Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them as a keyword argument instead.
scope parameter of @pytest.fixture can now be a callable that
receives the fixture name and the config object as keyword-only
parameters. See the
docs for
more information.--pastebin option: failures to connect to the
pastebin server are reported, without failing the pytest run--pastebin
to "text".--setup-only and --setup-show for custom pytest items.py.io.get_terminal_width for better
width detection.\#5807: Fix pypy3.6 (nightly) on windows.
\#2270: Fixed self reference in function-scoped fixtures defined plugin classes: previously self would be a reference to a *test* class, not the *plug
self reference in function-scoped fixtures defined plugin classes:
previously self would be a reference to a test class, not the
plugin class.--pastebin.pytest-xdist to display
them properly.conftest.py from a working directory that has casing other than
the one stored in the filesystem (e.g., c:\test instead of
C:\test).\#5751: Fixed TypeError when importing pytest on Python 3.5.0 and 3.5.1.
TypeError when importing pytest on Python 3.5.0 and 3.5.1.\#5180: As per our policy, the following features have been deprecated in the 4.X series and are now removed:
#5180: As per our policy, the following features have been deprecated in the 4.X series and are now removed:
Request.getfuncargvalue: use Request.getfixturevalue
instead.pytest.raises and pytest.warns no longer support strings as
the second argument.message parameter of pytest.raises.pytest.raises, pytest.warns and ParameterSet.param now use
native keyword-only syntax. This might change the exception
message from previous versions, but they still raise TypeError
on unknown keyword arguments as before.pytest.config global variable.tmpdir_factory.ensuretemp method.pytest_logwarning hook.RemovedInPytest4Warning warning type.request is now a reserved name for fixtures.For more information consult Deprecations and Removals in the docs.
#5565: Removed unused support code for unittest2.
The unittest2 backport module is no longer necessary since Python
3.3+, and the small amount of code in pytest to support it also
doesn't seem to be used: after removed, all tests still pass
unchanged.
Although our policy is to introduce a deprecation period before
removing any features or support for third party libraries, because
this code is apparently not used at all (even if unittest2 is used
by a test suite executed by pytest), it was decided to remove it in
this release.
If you experience a regression because of this, please file an issue.
#5615:
pytest.fail, pytest.xfail and pytest.skip no longer support
bytes for the message argument.
This was supported for Python 2 where it was tempting to use
"message" instead of u"message".
Python 3 code is unlikely to pass bytes to these functions. If you
do, please decode it to an str beforehand.
Config.invocation_args attribute containing the unchanged
arguments passed to pytest.main().#5471: JUnit XML now includes a timestamp and hostname in the testsuite tag.
#5707: Time taken to run the test suite now includes a human-readable representation when it takes over 60 seconds, for example:
===== 2 failed in 102.70s (0:01:42) =====
pytest_configure are explicitly not treated as
errors, even if configured as such, because it otherwise completely
breaks pytest.--junitxml now correctly contain a <testsuites>
root element.-vs) in Python 3.8+.tmp_path and tmpdir would not remove directories
containing files marked as read-only, which could lead to pytest
crashing when executed a second time with the --basetemp option.importlib_metadata backport with importlib.metadata from the
standard library on Python 3.8+.pytest.xfail,
pytest.skip, etc) so they provide better error messages when users
meant to use marks (for example @pytest.xfail instead of
@pytest.mark.xfail).numpy
arrays.pytest.exit is now correctly handled in unittest cases. This
makes unittest cases handle quit from pytest's pdb correctly.staticmethod objects defined with
functools.partial.async def functions.Testdir.copy_example.xunit2 family are now validated against the schema by
pytest's own test suite to avoid future regressions.SafeRepr class and removed some dead code.PYTHONDONTWRITEBYTECODE=1,
the test_xfail_handling test no longer fails.OSError.errno in the codebase by new OSError
subclasses (PermissionError, FileNotFoundError, etc.).\#5479: Improve quoting in raises match failure message.
raises match failure message.-vs) in Python 3.8+.--step-wise now handles xfail(strict=True) markers properly.Following our plan to remove deprecated features with as little disruption as possible, all warnings of type PytestDeprecationWarning now generate err…
This release is a Python3.5+ only release.
For more details, see our Python 2.7 and 3.4 support plan .
#1149 : Pytest no longer accepts prefixes of command-line arguments, for example typing pytest --doctest-mod inplace of --doctest-modules . This was previously allowed where the ArgumentParser thought it was unambiguous, but this could be incorrect due to delayed parsing of options for plugins. See for example issues #1149 , #3413 , and #4009 .
#5402 : PytestDeprecationWarning are now errors by default.
Following our plan to remove deprecated features with as little disruption as possible, all warnings of type PytestDeprecationWarning now generate errors instead of warning messages.
The affected features will be effectively removed in pytest 5.1 , so please consult the Deprecations and Removals section in the docs for directions on how to update existing code.
In the pytest 5.0.X series, it is possible to change the errors back into warnings as a stop gap measure by adding this to your pytest.ini file:
[pytest] filterwarnings = ignore : :pytest.PytestDeprecationWarning
But this will stop working when pytest 5.1 is released.
If you have concerns about the removal of a specific feature, please add a comment to #5402 .
#5412 : ExceptionInfo objects (returned by pytest.raises ) now have the same str representation as repr , which avoids some confusion when users use print(e) to inspect the object.
This means code like:
with pytest . raises ( SomeException ) as e : ... assert "some message" in str ( e )
Needs to be changed to:
with pytest . raises ( SomeException ) as e : ... assert "some message" in str ( e . value )
#4488 : The removal of the --result-log option and module has been postponed to (tentatively) pytest 6.0 as the team has not yet got around to implement a good alternative for it.
#466 : The funcargnames attribute has been an alias for fixturenames since pytest 2.3, and is now deprecated in code too.
#3457 : New pytest_assertion_pass hook, called with context information when an assertion passes .
This hook is still experimental so use it with caution.
#5440 : The faulthandler standard library module is now enabled by default to help users diagnose crashes in C modules.
This functionality was provided by integrating the external pytest-faulthandler plugin into the core, so users should remove that plugin from their requirements if used.
For more information see the docs: Fault Handler .
#5452 : When warnings are configured as errors, pytest warnings now appear as originating from pytest. instead of the internal _pytest.warning_types. module.
#5125 : Session.exitcode values are now coded in pytest.ExitCode , an IntEnum . This makes the exit code available for consumer code and are more explicit other than just documentation. User defined exit codes are still valid, but should be used with caution.
The team doesn’t expect this change to break test suites or plugins in general, except in esoteric/specific scenarios.
pytest-xdist users should upgrade to 1.29.0 or later, as pytest-xdist required a compatibility fix because of this change.
#1403 : Switch from imp to importlib .
#1671 : The name of the .pyc files cached by the assertion writer now includes the pytest version to avoid stale caches.
#2761 : Honor PEP 235 on case-insensitive file systems.
#5078 : Test module is no longer double-imported when using --pyargs .
#5260 : Improved comparison of byte strings.
When comparing bytes, the assertion message used to show the byte numeric value when showing the differences:
def test (): > assert b 'spam' == b 'eggs' E AssertionError : assert b 'spam' == b 'eggs' E At index 0 diff : 115 != 101 E Use - v to get the full diff
It now shows the actual ascii representation instead, which is often more useful:
def test (): > assert b 'spam' == b 'eggs' E AssertionError : assert b 'spam' == b 'eggs' E At index 0 diff : b 's' != b 'e' E Use - v to get the full diff
#5335 : Colorize level names when the level in the logging format is formatted using ‘%(levelname).Xs’ (truncated fixed width alignment), where X is an integer.
#5354 : Fix pytest.mark.parametrize when the argvalues is an iterator.
#5370 : Revert unrolling of all() to fix NameError on nested comprehensions.
#5371 : Revert unrolling of all() to fix incorrect handling of generators with if .
#5372 : Revert unrolling of all() to fix incorrect assertion when using all() in an expression.
#5383 : -q has again an impact on the style of the collected items ( --collect-only ) when --log-cli-level is used.
#5389 : Fix regressions of #5063 for importlib_metadata.PathDistribution which have their files attribute being None .
#5390 : Fix regression where the obj attribute of TestCase items was no longer bound to methods.
#5404 : Emit a warning when attempting to unwrap a broken object raises an exception, for easier debugging ( #5080 ).
#5432 : Prevent “already imported” warnings from assertion rewriter when invoking pytest in-process multiple times.
#5433 : Fix assertion rewriting in packages ( init.py ).
#5444 : Fix --stepwise mode when the first file passed on the command-line fails to collect.
#5482 : Fix bug introduced in 4.6.0 causing collection errors when passing more than 2 positional arguments to pytest.mark.parametrize .
#5505 : Fix crash when discovery fails while using -p no:terminal .
#5315 : Expand docs on mocking classes and dictionaries with monkeypatch .
#5416 : Fix PytestUnknownMarkWarning in run/skip example.
The upper case variants were never documented and the preferred form should be the lower case.
#6334: Fix summary entries appearing twice when f/F and s/S report chars were used at the same time in the -r command-line option (for example -rFf).
The upper case variants were never documented and the preferred form should be the lower case.
#7310: Fix UnboundLocalError: local variable 'letter' referenced before assignment in _pytest.terminal.pytest_report_teststatus()
when plugins return report objects in an unconventional state.
This was making pytest_report_teststatus() skip
entering if-block branches that declare the letter variable.
The fix was to set the initial value of the letter before
the if-block cascade so that it always has a value.
Remark: while this is technically a new feature and according to our policy it should not have been backported, we have opened an exception in this pa
#6870: New Config.invocation_args attribute containing the unchanged arguments passed to pytest.main().
Remark: while this is technically a new feature and according to our policy it should not have been backported, we have opened an exception in this particular case because it fixes a serious interaction with pytest-xdist, so it can also be considered a bugfix.
#6870 : New Config.invocation_args attribute containing the unchanged arguments passed to pytest.main() .
Remark: while this is technically a new feature and according to our policy it should not have been backported, we have opened an exception in this particular case because it fixes a serious interaction with pytest-xdist , so it can also be considered a bugfix.
#6404 : Remove usage of parser module, deprecated in Python 3.9.
\#6301: Fix assertion rewriting for egg-based distributions and editable installs (pip install --editable).
editable
installs (pip install --editable).\#5471: JUnit XML now includes a timestamp and hostname in the testsuite tag.
colorama to 0.4.1 only for Python 3.4 so newer Python versions
can still receive colorama updates.\#5477: The XML file produced by --junitxml now correctly contain a root element.
--junitxml now correctly contain a <testsuites>
root element.FileNotFoundError (OSError.errno == NOENT in Python 2)
exceptions when trying to remove old temporary directories, for
instance when multiple processes try to remove the same directory
(common with pytest-xdist for example).\#5902: Fix warnings about deprecated cmp attribute in attrs>=19.2.
-vs) in Python 3.8+.importlib_metadata backport with importlib.metadata from the
standard library on Python 3.8+.--pastebin
to "text".cmp attribute in attrs>=19.2.flake8-2020) in case python4
becomes a thing.Bug Fixes --------- - #4344: Fix RuntimeError/StopIteration when trying to collect package with "__init__.py" only. - #5478: Fix encode error when usi
#4344: Fix RuntimeError/StopIteration when trying to collect package with "init.py" only.
#5478: Fix encode error when using unicode strings in exceptions with pytest.raises.
#5524: Fix issue where tmp_path and tmpdir would not remove directories containing files marked as read-only,
which could lead to pytest crashing when executed a second time with the --basetemp option.
#5547: --step-wise now handles xfail(strict=True) markers properly.
#5650: Improved output when parsing an ini configuration file fails.
for easier debugging ( #5080 ).
#5404 : Emit a warning when attempting to unwrap a broken object raises an exception, for easier debugging ( #5080 ).
#5444 : Fix --stepwise mode when the first file passed on the command-line fails to collect.
#5482 : Fix bug introduced in 4.6.0 causing collection errors when passing more than 2 positional arguments to pytest.mark.parametrize .
#5505 : Fix crash when discovery fails while using -p no:terminal .
( --collect-only ) when --log-cli-level is used.
#5383 : -q has again an impact on the style of the collected items ( --collect-only ) when --log-cli-level is used.
#5389 : Fix regressions of #5063 for importlib_metadata.PathDistribution which have their files attribute being None .
#5390 : Fix regression where the obj attribute of TestCase items was no longer bound to methods.
### Bug Fixes - #5370 : Revert unrolling of all() to fix NameError on nested comprehensions. - #5371 : Revert unrolling of all() to fix incorrect hand
#5370 : Revert unrolling of all() to fix NameError on nested comprehensions.
#5371 : Revert unrolling of all() to fix incorrect handling of generators with if .
#5372 : Revert unrolling of all() to fix incorrect assertion when using all() in an expression.
### Bug Fixes - #5354 : Fix pytest.mark.parametrize when the argvalues is an iterator. - #5358 : Fix assertion rewriting of all() calls to deal with n
#5354 : Fix pytest.mark.parametrize when the argvalues is an iterator.
#5358 : Fix assertion rewriting of all() calls to deal with non-generators.
The 4.6.X series will be the last series to support Python 2 and Python 3.4 .
The 4.6.X series will be the last series to support Python 2 and Python 3.4 .
For more details, see our Python 2.7 and 3.4 support plan .
#4559 : Added the junit_log_passing_tests ini value which can be used to enable or disable logging of passing test output in the Junit XML file.
#4956 : pytester’s testdir.spawn uses tmpdir as HOME/USERPROFILE directory.
#5062 : Unroll calls to all to full for-loops with assertion rewriting for better failure messages, especially when using Generator Expressions.
#5063 : Switch from pkg_resources to importlib-metadata for entrypoint detection for improved performance and import time.
#5091 : The output for ini options in --help has been improved.
#5269 : pytest.importorskip includes the ImportError now in the default reason .
#5311 : Captured logs that are output for each failing test are formatted using the ColoredLevelFormatter.
#5312 : Improved formatting of multiline log messages in Python 3.
#2064 : The debugging plugin imports the wrapped Pdb class ( --pdbcls ) on-demand now.
#4908 : The pytest_enter_pdb hook gets called with post-mortem ( --pdb ).
#5036 : Fix issue where fixtures dependent on other parametrized fixtures would be erroneously parametrized.
#5256 : Handle internal error due to a lone surrogate unicode character not being representable in Jython.
#5257 : Ensure that sys.stdout.mode does not include 'b' as it is a text stream.
#5278 : Pytest’s internal python plugin can be disabled using -p no:python again.
#5286 : Fix issue with disable_test_id_escaping_and_forfeit_all_rights_to_community_support option not working when using a list of test IDs in parametrized tests.
#5330 : Show the test module being collected when emitting PytestCollectionWarning messages for test classes with init and new methods to make it easier to pin down the problem.
#5333 : Fix regression in 4.5.0 with --lf not re-running all tests with known failures from non-selected tests.
#5250 : Expand docs on use of setenv and delenv with monkeypatch .
it gets released: there are planned breaking changes, and we want to ensure pytest properly supports pluggy 1.0 .
#4826 : A warning is now emitted when unknown marks are used as a decorator. This is often due to a typo, which can lead to silently broken tests.
#4907 : Show XFail reason as part of JUnitXML message field.
#5013 : Messages from crash reports are displayed within test summaries now, truncated to the terminal width.
#5023 : New flag --strict-markers that triggers an error when unknown markers (e.g. those not registered using the markers option in the configuration file) are used in the test suite.
The existing --strict option has the same behavior currently, but can be augmented in the future for additional checks.
#5026 : Assertion failure messages for sequences and dicts contain the number of different items now.
#5034 : Improve reporting with --lf and --ff (run-last-failure).
#5035 : The --cache-show option/action accepts an optional glob to show only matching cache entries.
#5059 : Standard input (stdin) can be given to pytester’s Testdir.run() and Testdir.popen() .
#5068 : The -r option learnt about A to display all reports (including passed ones) in the short test summary.
#5108 : The short test summary is displayed after passes with output ( -rP ).
#5172 : The --last-failed ( --lf ) option got smarter and will now skip entire files if all tests of that test file have passed in previous runs, greatly speeding up collection.
#5177 : Introduce new specific warning PytestWarning subclasses to make it easier to filter warnings based on the class, rather than on the message. The new subclasses are:
PytestAssertRewriteWarning
PytestCacheWarning
PytestCollectionWarning
PytestConfigWarning
PytestUnhandledCoroutineWarning
PytestUnknownMarkWarning
#5202 : New record_testsuite_property session-scoped fixture allows users to log <property> tags at the testsuite level with the junitxml plugin.
The generated XML is compatible with the latest xunit standard, contrary to the properties recorded by record_property and record_xml_attribute .
#5214 : The default logging format has been changed to improve readability. Here is an example of a previous logging message:
test_log_cli_enabled_disabled . py 3 CRITICAL critical message logged by test
This has now become:
CRITICAL root : test_log_cli_enabled_disabled . py : 3 critical message logged by test
The formatting can be changed through the log_format configuration option.
#5220 : --fixtures now also shows fixture scope for scopes other than "function" .
#5113 : Deselected items from plugins using pytest_collect_modifyitems as a hookwrapper are correctly reported now.
#5144 : With usage errors exitstatus is set to EXIT_USAGEERROR in the pytest_sessionfinish hook now as expected.
#5235 : outcome.exit is not used with EOF in the pdb wrapper anymore, but only with quit .
#4935 : Expand docs on registering marks and the effect of --strict .
#4942 : logging.raiseExceptions is not set to False anymore.
#5013 : pytest now depends on wcwidth to properly track unicode character sizes for more precise terminal output.
#5059 : pytester’s Testdir.popen() uses stdout and stderr via keyword arguments with defaults now ( subprocess.PIPE ).
#5069 : The code for the short test summary in the terminal was moved to the terminal plugin.
#5082 : Improved validation of kwargs for various methods in the pytester plugin.
#5202 : record_property now emits a PytestWarning when used with junit_family=xunit2 : the fixture generates property tags as children of testcase , which is not permitted according to the most recent schema .
#5239 : Pin pluggy to < 1.0 so we don’t update to 1.0 automatically when it gets released: there are planned breaking changes, and we want to ensure pytest properly supports pluggy 1.0 .
The importlib-metadata package cannot be imported when installed as an egg and causes issues when relying on setup.py to install test dependencies.
#5089 : Fix crash caused by error in repr function with both showlocals and verbose output enabled.
#5139 : Eliminate core dependency on ‘terminal’ plugin.
#5229 : Require pluggy>=0.11.0 which reverts a dependency to importlib-metadata added in 0.10.0 . The importlib-metadata package cannot be imported when installed as an egg and causes issues when relying on setup.py to install test dependencies.
#5171 : Doc: pytest_ignore_collect , pytest_collect_directory , pytest_collect_file and pytest_pycollect_makemodule hooks’s ‘path’ parameter documented type is now py.path.local
#5188 : Improve help for --runxfail flag.
#5182 : Removed internal and unused _pytest.deprecated.MARK_INFO_ATTRIBUTE .
### Bug Fixes - #5031 : Environment variables are properly restored when using pytester’s testdir fixture. - #5039 : Fix regression with --pdbcls , wh
#5031 : Environment variables are properly restored when using pytester’s testdir fixture.
#5039 : Fix regression with --pdbcls , which stopped working with local modules in 4.0.0.
#5092 : Produce a warning when unknown keywords are passed to pytest.param(...) .
#5098 : Invalidate import caches with monkeypatch.syspath_prepend , which is required with namespace packages being used.
async plugin is not installed (such as pytest-asyncio or pytest-trio ).
#2224 : async test functions are skipped and a warning is emitted when a suitable async plugin is not installed (such as pytest-asyncio or pytest-trio ).
Previously async functions would not execute at all but still be marked as “passed”.
#2482 : Include new disable_test_id_escaping_and_forfeit_all_rights_to_community_support option to disable ascii-escaping in parametrized values. This may cause a series of problems and as the name makes clear, use at your own risk.
#4718 : The -p option can now be used to early-load plugins also by entry-point name, instead of just by module name.
This makes it possible to early load external plugins like pytest-cov in the command-line:
pytest - p pytest_cov
#4855 : The --pdbcls option handles classes via module attributes now (e.g. pdb:pdb.Pdb with pdbpp ), and its validation was improved.
#4875 : The testpaths configuration option is now displayed next to the rootdir and inifile lines in the pytest header if the option is in effect, i.e., directories or file names were not explicitly passed in the command line.
Also, inifile is only displayed if there’s a configuration file, instead of an empty inifile: string.
#4911 : Doctests can be skipped now dynamically using pytest.skip() .
#4920 : Internal refactorings have been made in order to make the implementation of the pytest-subtests plugin possible, which adds unittest sub-test support and a new subtests fixture as discussed in #1367 .
For details on the internal refactorings, please see the details on the related PR.
#4931 : pytester’s LineMatcher asserts that the passed lines are a sequence.
#4936 : Handle -p plug after -p no:plug .
This can be used to override a blocked plugin (e.g. in “addopts”) from the command line etc.
#4951 : Output capturing is handled correctly when only capturing via fixtures (capsys, capfs) with pdb.set_trace() .
#4956 : pytester sets $HOME and $USERPROFILE to the temporary directory during test runs.
This ensures to not load configuration files from the real user’s home directory.
#4980 : Namespace packages are handled better with monkeypatch.syspath_prepend and testdir.syspathinsert (via pkg_resources.fixup_namespace_packages ).
#4993 : The stepwise plugin reports status information now.
#5008 : If a setup.cfg file contains [tool:pytest] and also the no longer supported [pytest] section, pytest will use [tool:pytest] ignoring [pytest] . Previously it would unconditionally error out.
This makes it simpler for plugins to support old pytest versions.
#1895 : Fix bug where fixtures requested dynamically via request.getfixturevalue() might be teardown before the requesting fixture.
#4851 : pytester unsets PYTEST_ADDOPTS now to not use outer options with testdir.runpytest() .
#4903 : Use the correct modified time for years after 2038 in rewritten .pyc files.
#4928 : Fix line offsets with ScopeMismatch errors.
#4957 : -p no:plugin is handled correctly for default (internal) plugins now, e.g. with -p no:capture .
Previously they were loaded (imported) always, making e.g. the capfd fixture available.
#4968 : The pdb quit command is handled properly when used after the debug command with pdbpp .
#4975 : Fix the interpretation of -qq option where it was being considered as -v instead.
#4978 : outcomes.Exit is not swallowed in assertrepr_compare anymore.
#4988 : Close logging’s file handler explicitly when the session finishes.
#5003 : Fix line offset with mark collection error (off by one).
#4974 : Update docs for pytest_cmdline_parse hook to note availability limitations
#4718 : pluggy>=0.9 is now required.
#4815 : funcsigs>=1.0 is now required for Python 2.7.
#4829 : Some left-over internal code related to yield tests has been removed.
#4890 : Remove internally unused anypython fixture from the pytester plugin.
#4912 : Remove deprecated Sphinx directive, add_description_unit() , pin sphinx-removed-in to >= 0.2.0 to support Sphinx 2.0.
#4913 : Fix pytest tests invocation with custom PYTHONPATH .
#4965 : New pytest_report_to_serializable and pytest_report_from_serializable experimental hooks.
These hooks will be used by pytest-xdist , pytest-subtests , and the replacement for resultlog to serialize and customize reports.
They are experimental, meaning that their details might change or even be removed completely in future patch releases without warning.
Feedback is welcome from plugin authors and users alike.
#4987 : Collector.repr_failure respects the --tb option, but only defaults to short now (with auto ).
### Bug Fixes - #4810 : Logging messages inside pytest_runtest_logreport() are now properly captured and displayed. - #4861 : Improve validation of co
#4810 : Logging messages inside pytest_runtest_logreport() are now properly captured and displayed.
#4861 : Improve validation of contents written to captured output so it behaves the same as when capture is disabled.
#4898 : Fix AttributeError: FixtureRequest has no 'confg' attribute bug in testdir.copy_example .
#4768 : Avoid pkg_resources import at the top-level.
This will be changed into an error in the future.
#4724 : pytest.warns() now emits a warning when it receives unknown keyword arguments.
This will be changed into an error in the future.
#2753 : Usage errors from argparse are mapped to pytest’s UsageError .
#3711 : Add the --ignore-glob parameter to exclude test-modules with Unix shell-style wildcards. Add the collect_ignore_glob for conftest.py to exclude test-modules with Unix shell-style wildcards.
#4698 : The warning about Python 2.7 and 3.4 not being supported in pytest 5.0 has been removed.
In the end it was considered to be more of a nuisance than actual utility and users of those Python versions shouldn’t have problems as pip will not install pytest 5.0 on those interpreters.
#4707 : With the help of new set_log_path() method there is a way to set log_file paths from hooks.
#4651 : --help and --version are handled with UsageError .
#4782 : Fix AssertionError with collection of broken symlinks with packages.
were skipped by a unittest.skip() decorator applied in the subclass.
#2895 : The pytest_report_collectionfinish hook now is also called with --collect-only .
#3899 : Do not raise UsageError when an imported package has a pytest_plugins.py child module.
#4347 : Fix output capturing when using pdb++ with recursive debugging.
#4592 : Fix handling of collect_ignore via parent conftest.py .
#4700 : Fix regression where setUpClass would always be called in subclasses even if all tests were skipped by a unittest.skip() decorator applied in the subclass.
#4739 : Fix parametrize(... ids=<function>) when the function returns non-strings.
#4745 : Fix/improve collection of args when passing in init.py and a test file.
#4770 : more_itertools is now constrained to <6.0.0 when required for Python 2.7 compatibility.
#526 : Fix “ValueError: Plugin already registered” exceptions when running in build directories that symlink to actual source.
#3899 : Add note to plugins.rst that pytest_plugins should not be used as a name for a user module containing plugins.
#4324 : Document how to use raises and does_not_raise to write parametrized tests with conditional raises.
#4709 : Document how to customize test failure messages when using pytest.warns .
#4741 : Some verbosity related attributes of the TerminalReporter plugin are now read only properties.
np.asscalar has been deprecated in numpy 1.16. .
#3094 : Classic xunit-style functions and methods now obey the scope of autouse fixtures.
This fixes a number of surprising issues like setup_method being called before session-scoped autouse fixtures (see #517 for an example).
#4627 : Display a message at the end of the test session when running under Python 2.7 and 3.4 that pytest 5.0 will no longer support those Python versions.
#4660 : The number of selected tests now are also displayed when the -k or -m flags are used.
#4688 : pytest_report_teststatus hook now can also receive a config parameter.
#4691 : pytest_terminal_summary hook now can also receive a config parameter.
#3547 : --junitxml can emit XML compatible with Jenkins xUnit. junit_family INI option accepts legacy|xunit1 , which produces old style output, and xunit2 that conforms more strictly to https://github.com/jenkinsci/xunit-plugin/blob/xunit-2.3.2/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
#4280 : Improve quitting from pdb, especially with --trace .
Using q[quit] after pdb.set_trace() will quit pytest also.
#4402 : Warning summary now groups warnings by message instead of by test id.
This makes the output more compact and better conveys the general idea of how much code is actually generating warnings, instead of how many tests call that code.
#4536 : monkeypatch.delattr handles class descriptors like staticmethod / classmethod .
#4649 : Restore marks being considered keywords for keyword expressions.
#4653 : tmp_path fixture and other related ones provides resolved path (a.k.a real path)
#4667 : pytest_terminal_summary uses result from pytest_report_teststatus hook, rather than hardcoded strings.
#4669 : Correctly handle unittest.SkipTest exception containing non-ascii characters on Python 2.
#4680 : Ensure the tmpdir and the tmp_path fixtures are the same folder.
#4681 : Ensure tmp_path is always a real path.
#4643 : Use a.item() instead of the deprecated np.asscalar(a) in pytest.approx .
np.asscalar has been deprecated in numpy 1.16. .
#4657 : Copy saferepr from pylib
#4668 : The verbose word for expected failures in the teststatus report changes from xfail to XFAIL to be consistent with other test outcomes.
### Bug Fixes - #2256 : Show full repr with assert a==b and -vv . - #3456 : Extend Doctest-modules to ignore mock objects. - #4617 : Fixed pytest.warn
#2256 : Show full repr with assert a==b and -vv .
#3456 : Extend Doctest-modules to ignore mock objects.
#4617 : Fixed pytest.warns bug when context manager is reused (e.g. multiple parametrization).
#4631 : Don’t rewrite assertion when getattr is broken
#3375 : Document that using setup.cfg may crash other tools or cause hard to track down problems because it uses a different parser than pytest.ini or tox.ini files.
#4602 : Uninstall hypothesis in regen tox env.
To avoid this mistake and because it is believed to be little used, pytest is deprecating it without providing an alternative for the moment.
#2169 : pytest.mark.parametrize : in previous versions, errors raised by id functions were suppressed and changed into warnings. Now the exceptions are propagated, along with a pytest message informing the node, parameter value and index where the exception occurred.
#3078 : Remove legacy internal warnings system: config.warn , Node.warn . The pytest_logwarning now issues a warning when implemented.
See our docs on information on how to update your code.
#3079 : Removed support for yield tests - they are fundamentally broken because they don’t support fixtures properly since collection and test execution were separated.
See our docs on information on how to update your code.
#3082 : Removed support for applying marks directly to values in @pytest.mark.parametrize . Use pytest.param instead.
See our docs on information on how to update your code.
#3083 : Removed Metafunc.addcall . This was the predecessor mechanism to @pytest.mark.parametrize .
See our docs on information on how to update your code.
#3085 : Removed support for passing strings to pytest.main . Now, always pass a list of strings instead.
See our docs on information on how to update your code.
#3086 : [pytest] section in setup.cfg files is no longer supported, use [tool:pytest] instead. setup.cfg files are meant for use with distutils , and a section named pytest has notoriously been a source of conflicts and bugs.
Note that for pytest.ini and tox.ini files the section remains [pytest] .
#3616 : Removed the deprecated compat properties for node.Class/Function/Module - use pytest.Class/Function/Module now.
See our docs on information on how to update your code.
#4421 : Removed the implementation of the pytest_namespace hook.
See our docs on information on how to update your code.
#4489 : Removed request.cached_setup . This was the predecessor mechanism to modern fixtures.
See our docs on information on how to update your code.
#4535 : Removed the deprecated PyCollector.makeitem method. This method was made public by mistake a long time ago.
#4543 : Removed support to define fixtures using the pytest_funcarg__ prefix. Use the @pytest.fixture decorator instead.
See our docs on information on how to update your code.
#4545 : Calling fixtures directly is now always an error instead of a warning.
See our docs on information on how to update your code.
#4546 : Remove Node.get_marker(name) the return value was not usable for more than an existence check.
Use Node.get_closest_marker(name) as a replacement.
#4547 : The deprecated record_xml_property fixture has been removed, use the more generic record_property instead.
See our docs for more information.
#4548 : An error is now raised if the pytest_plugins variable is defined in a non-top-level conftest.py file (i.e., not residing in the rootdir ).
See our docs for more information.
#891 : Remove testfunction.markername attributes - use Node.iter_markers(name=None) to iterate them.
#3050 : Deprecated the pytest.config global.
See pytest.config global for rationale.
#3974 : Passing the message parameter of pytest.raises now issues a DeprecationWarning .
It is a common mistake to think this parameter will match the exception message, while in fact it only serves to provide a custom message in case the pytest.raises check fails. To avoid this mistake and because it is believed to be little used, pytest is deprecating it without providing an alternative for the moment.
If you have concerns about this, please comment on #3974 .
#4435 : Deprecated raises(..., 'code(as_a_string)') and warns(..., 'code(as_a_string)') .
See raises / warns with a string as the second argument for rationale and examples.
#3191 : A warning is now issued when assertions are made for None .
This is a common source of confusion among new users, which write:
assert mocked_object . assert_called_with ( 3 , 4 , 5 , key = "value" )
When they should write:
mocked_object . assert_called_with ( 3 , 4 , 5 , key = "value" )
Because the assert_called_with method of mock objects already executes an assertion.
This warning will not be issued when None is explicitly checked. An assertion like:
assert variable is None
will not issue the warning.
#3632 : Richer equality comparison introspection on AssertionError for objects created using attrs or dataclasses (Python 3.7+, backported to 3.6 ).
#4278 : CACHEDIR.TAG files are now created inside cache directories.
Those files are part of the Cache Directory Tagging Standard , and can be used by backup or synchronization programs to identify pytest’s cache directory as such.
#4292 : pytest.outcomes.Exit is derived from SystemExit instead of KeyboardInterrupt . This allows us to better handle pdb exiting.
#4371 : Updated the --collect-only option to display test descriptions when ran using --verbose .
#4386 : Restructured ExceptionInfo object construction and ensure incomplete instances have a repr / str .
#4416 : pdb: added support for keyword arguments with pdb.set_trace .
It handles header similar to Python 3.7 does it, and forwards any other keyword arguments to the Pdb constructor.
This allows for import("pdb").set_trace(skip=["foo.*"]) .
#4483 : Added ini parameter junit_duration_report to optionally report test call durations, excluding setup and teardown times.
The JUnit XML specification and the default pytest behavior is to include setup and teardown times in the test duration report. You can include just the call durations instead (excluding setup and teardown) by adding this to your pytest.ini file:
[pytest] junit_duration_report = call
#4532 : -ra now will show errors and failures last, instead of as the first items in the summary.
This makes it easier to obtain a list of errors and failures to run tests selectively.
#4599 : pytest.importorskip now supports a reason parameter, which will be shown when the requested module cannot be imported.
#3532 : -p now accepts its argument without a space between the value, for example -pmyplugin .
#4327 : approx again works with more generic containers, more precisely instances of Iterable and Sized instead of more restrictive Sequence .
#4397 : Ensure that node ids are printable.
#4435 : Fixed raises(..., 'code(string)') frame filename.
#4458 : Display actual test ids in --collect-only .
#4557 : Markers example documentation page updated to support latest pytest version.
#4558 : Update cache documentation example to correctly show cache hit and miss.
#4580 : Improved detailed summary report documentation.
#4447 : Changed the deprecation type of --result-log to PytestDeprecationWarning .
It was decided to remove this feature at the next major revision.
### Bug Fixes - #4265 : Validate arguments from the PYTEST_ADDOPTS environment variable and the addopts ini option separately. - #4435 : Fix raises(..
#4265 : Validate arguments from the PYTEST_ADDOPTS environment variable and the addopts ini option separately.
#4435 : Fix raises(..., 'code(string)') frame filename.
#4500 : When a fixture yields and a log call is made after the test runs, and, if the test is interrupted, capture attributes are None .
#4538 : Raise TypeError for with raises(..., match=<non-None falsey value>) .
#1495 : Document common doctest fixture directory tree structure pitfalls
### Bug Fixes - #3952 : Display warnings before “short test summary info” again, but still later warnings in the end. - #4386 : Handle uninitialized e
#3952 : Display warnings before “short test summary info” again, but still later warnings in the end.
#4386 : Handle uninitialized exceptioninfo in repr/str.
#4393 : Do not create .gitignore / README.md files in existing cache directories.
#4400 : Rearrange warning handling for the yield test errors so the opt-out in 4.0.x correctly works.
#4405 : Fix collection of testpaths with --pyargs .
#4412 : Fix assertion rewriting involving Starred + side-effects.
#4425 : Ensure we resolve the absolute path when the given --basetemp is a relative path.
#4315 : Use pkg_resources.parse_version instead of LooseVersion in minversion check.
#4440 : Adjust the stack level of some internal pytest warnings.
Following our plan to remove deprecated features with as little disruption as possible, all warnings of type RemovedInPytest4Warnings now generate err…
#3737 : RemovedInPytest4Warnings are now errors by default.
Following our plan to remove deprecated features with as little disruption as possible, all warnings of type RemovedInPytest4Warnings now generate errors instead of warning messages.
The affected features will be effectively removed in pytest 4.1 , so please consult the Deprecations and Removals section in the docs for directions on how to update existing code.
In the pytest 4.0.X series, it is possible to change the errors back into warnings as a stop gap measure by adding this to your pytest.ini file:
[pytest] filterwarnings = ignore : :pytest.RemovedInPytest4Warning
But this will stop working when pytest 4.1 is released.
If you have concerns about the removal of a specific feature, please add a comment to #4348 .
#4358 : Remove the ::() notation to denote a test class instance in node ids.
Previously, node ids that contain test instances would use ::() to denote the instance like this:
test_foo . py :: Test ::():: test_bar
The extra ::() was puzzling to most users and has been removed, so that the test id becomes now:
test_foo . py :: Test :: test_bar
This change could not accompany a deprecation period as is usual when user-facing functionality changes because it was not really possible to detect when the functionality was being used explicitly.
The extra ::() might have been removed in some places internally already, which then led to confusion in places where it was expected, e.g. with --deselect ( #4127 ).
Test class instances are also not listed with --collect-only anymore.
#4270 : The cache_dir option uses $TOX_ENV_DIR as prefix (if set in the environment).
This uses a different cache per tox environment by default.
#3554 : Fix CallInfo.repr for when the call is not finished yet.
One column per quarter.