NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #24 most downloaded on PyPI
pytest: simple powerful testing with Python
Last release 3 months ago
19 Jun 2026
Ships fairly regularly
a new release about every 2 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
1 version withdrawn
withdrawn after publishing
16 years old
192 releases · first in 2010
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.One column per quarter.
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.
### Bug Fixes - #4287 : Fix nested usage of debugging plugin (pdb), e.g. with pytester’s testdir.runpytest . - #4304 : Block the stepwise plugin if ca
#4287 : Fix nested usage of debugging plugin (pdb), e.g. with pytester’s testdir.runpytest .
#4304 : Block the stepwise plugin if cacheprovider is also blocked, as one depends on the other.
#4306 : Parse minversion as an actual version and not as dot-separated strings.
#4310 : Fix duplicate collection due to multiple args matching the same packages.
#4321 : Fix item.nodeid with resolved symlinks.
#4325 : Fix collection of direct symlinked files, where the target does not match python_files .
#4329 : Fix TypeError in report_collect with _collect_report_last_write.
#4305 : Replace byte/unicode helpers in test_capture with python level syntax.
This also adds a new pytest_leave_pdb hook, and passes in pdb to the existing pytest_enter_pdb hook.
#2619 : Resume capturing output after continue with import("pdb").set_trace() .
This also adds a new pytest_leave_pdb hook, and passes in pdb to the existing pytest_enter_pdb hook.
#4147 : Add --sw , --stepwise as an alternative to --lf -x for stopping at the first failure, but starting the next test invocation from that test. See the documentation for more info.
#4188 : Make --color emit colorful dots when not running in verbose mode. Earlier, it would only colorize the test-by-test output if --verbose was also passed.
#4225 : Improve performance with collection reporting in non-quiet mode with terminals.
The “collecting …” message is only printed/updated every 0.5s.
#2701 : Fix false RemovedInPytest4Warning: usage of Session... is deprecated, please use pytest warnings.
#4046 : Fix problems with running tests in package init.py files.
#4260 : Swallow warnings during anonymous compilation of source.
#4262 : Fix access denied error when deleting stale directories created by tmpdir / tmp_path .
#611 : Naming a fixture request will now raise a warning: the request fixture is internal and should not be overwritten as it will lead to internal errors.
#4266 : Handle (ignore) exceptions raised during collection, e.g. with Django’s LazySettings proxy class.
#4255 : Added missing documentation about the fact that module names passed to filter warnings are not regex-escaped.
#4272 : Display cachedir also in non-verbose mode if non-default.
#4277 : pdb: improve message about output capturing with set_trace .
Do not display “IO-capturing turned off/on” when -s is used to avoid confusion.
#4279 : Improve message and stack level of warnings issued by monkeypatch.setenv when the value of the environment variable is not a str .
### Bug Fixes - #4174 : Fix “ValueError: Plugin already registered” with conftest plugins via symlink. - #4181 : Handle race condition between creatio
#4174 : Fix “ValueError: Plugin already registered” with conftest plugins via symlink.
#4181 : Handle race condition between creation and deletion of temporary folders.
#4221 : Fix bug where the warning summary at the end of the test session was not showing the test where the warning was originated.
#4243 : Fix regression when stacklevel for warnings was passed as positional argument on python2.
#3851 : Add reference to empty_parameter_set_mark ini option in documentation of @pytest.mark.parametrize
#4028 : Revert patching of sys.breakpointhook since it appears to do nothing.
#4233 : Apply an import sorter ( reorder-python-imports ) to the codebase.
#4248 : Remove use of unnecessary compat shim, six.binary_type
surprising MemoryError exception when monkey patching warnings.warn itself.
#2909 : Improve error message when a recursive dependency between fixtures is detected.
#3340 : Fix logging messages not shown in hooks pytest_sessionstart() and pytest_sessionfinish() .
#3533 : Fix unescaped XML raw objects in JUnit report for skipped tests
#3691 : Python 2: safely format warning message about passing unicode strings to warnings.warn , which may cause surprising MemoryError exception when monkey patching warnings.warn itself.
#4026 : Improve error message when it is not possible to determine a function’s signature.
#4177 : Pin setuptools>=40.0 to support py_modules in setup.cfg
#4179 : Restore the tmpdir behaviour of symlinking the current test run.
#4192 : Fix filename reported by warnings.warn when using recwarn under python2.
module is now output only if a higher verbosity level is specified (at least “-vv”).
#4159 : For test-suites containing test classes, the information about the subclassed module is now output only if a higher verbosity level is specified (at least “-vv”).
Our policy is to not deprecate features during bug-fix releases, but in this case we believe it makes sense as we are only documenting it as deprecate…
#4036 : The item parameter of pytest_warning_captured hook is now documented as deprecated. We realized only after the 3.8 release that this parameter is incompatible with pytest-xdist .
Our policy is to not deprecate features during bug-fix releases, but in this case we believe it makes sense as we are only documenting it as deprecated, without issuing warnings which might potentially break test suites. This will get the word out that hook implementers should not use this parameter at all.
In a future release item will always be None and will emit a proper warning when a hook implementation makes use of it.
#3539 : Fix reload on assertion rewritten modules.
#4034 : The .user_properties attribute of TestReport objects is a list of (name, value) tuples, but could sometimes be instantiated as a tuple of tuples. It is now always a list.
#4039 : No longer issue warnings about using pytest_plugins in non-top-level directories when using --pyargs : the current --pyargs mechanism is not reliable and might give false negatives.
#4040 : Exclude empty reports for passed tests when -rP option is used.
#4051 : Improve error message when an invalid Python expression is passed to the -m option.
#4056 : MonkeyPatch.setenv and MonkeyPatch.delenv issue a warning if the environment variable name is not str on Python 2.
In Python 2, adding unicode keys to os.environ causes problems with subprocess (and possible other modules), making this a subtle bug specially susceptible when used with from future import unicode_literals .
#3928 : Add possible values for fixture scope to docs.
deprecated features, the rationale to do so, and alternatives to update your code. It also list features removed from pytest in past major releases to…
#3286 : .pytest_cache directory is now automatically ignored by Git. Users who would like to contribute a solution for other SCMs please consult/comment on this issue.
#3749 : Fix the following error during collection of tests inside packages:
TypeError : object of type 'Package' has no len ()
#3941 : Fix bug where indirect parametrization would consider the scope of all fixtures used by the test function to determine the parametrization scope, and not only the scope of the fixtures being parametrized.
#3973 : Fix crash of the assertion rewriter if a test changed the current working directory without restoring it afterwards.
#3998 : Fix issue that prevented some caplog properties (for example record_tuples ) from being available when entering the debugger with --pdb .
#3999 : Fix UnicodeDecodeError in python2.x when a class returns a non-ascii binary repr in an assertion which also contains non-ascii text.
#3996 : New Deprecations and Removals page shows all currently deprecated features, the rationale to do so, and alternatives to update your code. It also list features removed from pytest in past major releases to help those with ancient pytest versions to upgrade.
#3955 : Improve pre-commit detection for changelog filenames
#3975 : Remove legacy code around im_func as that was python2 only
deprecated, see Config.warn and Node.warn for rationale and examples.
#2452 : Config.warn and Node.warn have been deprecated, see Config.warn and Node.warn for rationale and examples.
#3936 : @pytest.mark.filterwarnings second parameter is no longer regex-escaped, making it possible to actually use regular expressions to check the warning message.
Note : regex-escaping the match string was an implementation oversight that might break test suites which depend on the old behavior.
#2452 : Internal pytest warnings are now issued using the standard warnings module, making it possible to use the standard warnings filters to manage those warnings. This introduces PytestWarning , PytestDeprecationWarning and RemovedInPytest4Warning warning types as part of the public API.
Consult the documentation for more info.
#2908 : DeprecationWarning and PendingDeprecationWarning are now shown by default if no other warning filter is configured. This makes pytest more compliant with PEP 506#recommended-filter-settings-for-test-runners . See the docs for more info.
#3251 : Warnings are now captured and displayed during test collection.
#3784 : PYTEST_DISABLE_PLUGIN_AUTOLOAD environment variable disables plugin auto-loading when set.
#3829 : Added the count option to console_output_style to enable displaying the progress as a count instead of a percentage.
#3837 : Added support for ‘xfailed’ and ‘xpassed’ outcomes to the pytester.RunResult.assert_outcomes signature.
#3911 : Terminal writer now takes into account unicode character width when writing out progress.
#3913 : Pytest now returns with correct exit code (EXIT_USAGEERROR, 4) when called with unknown arguments.
#3918 : Improve performance of assertion rewriting.
#3566 : Added a blurb in usage.rst for the usage of -r flag which is used to show an extra test summary info.
#3907 : Corrected type of the exceptions collection passed to xfail : raises argument accepts a tuple instead of list .
#3853 : Removed "run all (no recorded failures)" message printed with --failed-first and --last-failed when there are no failed tests.
### Bug Fixes - #3506 : Fix possible infinite recursion when writing .pyc files. - #3853 : Cache plugin now obeys the -q flag when --last-failed and -
#3506 : Fix possible infinite recursion when writing .pyc files.
#3853 : Cache plugin now obeys the -q flag when --last-failed and --failed-first flags are used.
#3883 : Fix bad console output when using console_output_style=classic .
#3888 : Fix macOS specific code using capturemanager plugin in doctests.
#3902 : Fix pytest.org links
### Bug Fixes - #3033 : Fixtures during teardown can again use capsys and capfd to inspect output captured during tests. - #3773 : Fix collection of t
#3033 : Fixtures during teardown can again use capsys and capfd to inspect output captured during tests.
#3773 : Fix collection of tests from init.py files if they match the python_files configuration option.
#3796 : Fix issue where teardown of fixtures of consecutive sub-packages were executed once, at the end of the outer package.
#3816 : Fix bug where --show-capture=no option would still show logs printed during fixture teardown.
#3819 : Fix stdout/stderr not getting captured when real-time cli logging is active.
#3843 : Fix collection error when specifying test functions directly in the command line using test.py::test syntax together with --doctest-modules .
#3848 : Fix bugs where unicode arguments could not be passed to testdir.runpytest on Python 2.
#3854 : Fix double collection of tests within packages when the filename starts with a capital letter.
#3824 : Added example for multiple glob pattern matches in python_files .
#3833 : Added missing docs for pytester.Testdir .
#3870 : Correct documentation for setuptools integration.
#3826 : Replace broken type annotations with type comments.
#3845 : Remove a reference to issue #568 from the documentation, which has since been fixed.
### Bug Fixes - #3671 : Fix filterwarnings not being registered as a builtin mark. - #3768 , #3789 : Fix test collection from packages mixed with norm
#3671 : Fix filterwarnings not being registered as a builtin mark.
#3768 , #3789 : Fix test collection from packages mixed with normal directories.
#3771 : Fix infinite recursion during collection if a pytest_ignore_collect hook returns False instead of None .
#3774 : Fix bug where decorated fixtures would lose functionality (for example @mock.patch ).
#3775 : Fix bug where importing modules or other objects with prefix pytest_ prefix would raise a PluginValidationError .
#3788 : Fix AttributeError during teardown of TestCase subclasses which raise an exception during init .
#3804 : Fix traceback reporting for exceptions with cause cycles.
#3746 : Add documentation for metafunc.config that had been mistakenly hidden.
### Bug Fixes - #3473 : Raise immediately if approx() is given an expected value of a type it doesn’t understand (e.g. strings, nested dicts, etc.). -
#3473 : Raise immediately if approx() is given an expected value of a type it doesn’t understand (e.g. strings, nested dicts, etc.).
#3712 : Correctly represent the dimensions of a numpy array when calling repr() on approx() .
#3742 : Fix incompatibility with third party plugins during collection, which produced the error object has no attribute '_collectfile' .
#3745 : Display the absolute path if cache_dir is not relative to the rootdir instead of failing.
#3747 : Fix compatibility problem with plugins and the warning code issued by fixture functions when they are called directly.
#3748 : Fix infinite recursion in pytest.approx with arrays in numpy<1.13 .
#3757 : Pin pathlib2 to >=2.2.0 as we require fspath support.
#3763 : Fix TypeError when the assertion message is bytes in python 3.
Your coding agent can read these notes before it upgrades. Set up the MCP server →