Upgrading pytest 5 to 6
Breaking5.4.3 → 6.2.5Breaking16Security1Platform1Deprecated10New23Changed40Fixed63Other17
SecurityCreates temporary directories under /tmp with private permissions and errors if a pre-existing pytest-of-<username> directory is owned by another user.#8414 ↗
BreakingUpgrade verdict
16 breaking changes and a platform requirement change and a security fix.
In plain terms
- Deprecated pytest features now fail your test run instead of just warning you.
- Removes the exec_() and is_true() methods of _pytest._code.Frame.
- Test selection expressions for -m and -k are now parsed by pytest itself instead of Python, so Python constants, keywords and other operators no longer work there.
- Two internal logging attributes are gone, and the old --no-print-logs flag was removed in favor of --show-capture.
Must act Top 5 of 28 that need code or config changes
Python requirement changed in 6.2.0: >=3.5 → >=3.6.
Adds iniconfig, toml.
Drops more-itertools, wcwidth.
What you must change
Breaking16
PytestDeprecationWarning warnings are now errors by default; affected features will be removed in pytest 6.1.
PytestDeprecationWarningfilterwarningsRemoves the exec_() and is_true() methods of _pytest._code.Frame.
_pytest._code.Frame.exec_()_pytest._code.Frame.is_true()Expressions given to -m and -k are no longer evaluated using Python's eval; only or, and, not, parentheses and identifiers are supported.
-m-kRemoves the item.catch_log_handler and item.catch_log_handlers attributes and the deprecated --no-print-logs option.
item.catch_log_handleritem.catch_log_handlers--no-print-logs--show-captureRemoves the unused args parameter from pytest.Function.__init__.
pytest.Function.__init__Removes the pytest_doctest_prepare_content hook specification, which has not been triggered for at least 10 years.
pytest_doctest_prepare_contentpytest now supports Python 3.6 and newer only.
Removes features deprecated in the 5.X series: funcargnames, positional fixture args, direct Node construction, junit_family default, TerminalReporter.writer, and --result-log.
FixtureRequest.funcargnamesMetafunc.funcargnamesFunction.funcargnamespytest.fixtureNodejunit_familyTerminalReporter.writer--result-logSymlinks are no longer resolved during collection and matching conftest.py files with test file paths.
conftest.pyTestdir.run().parseoutcomes() now always returns parsed nouns in plural form.
Testdir.run()parseoutcomes()assert_outcomesThe os.dup() function is now assumed to exist.
os.dup()-k no longer matches directory names outside the test session root, and pytest.Package.name is now just the package directory name.
-kpytest.Package.name__init__.pyPytest uses its own TerminalWriter class instead of the py library one, with several breaking changes to its API and behavior.
TerminalWriterTerminalReporter.writerTerminalReporter.write()_pytest.config.create_terminal_writer()write(flush=True)terminal_writer.flush()relinechars_on_current_lineRemoves several internal _pytest._code.source APIs, including Source arguments, comparison with str, and compile/getsource helpers.
_pytest._code.sourceSource()Source.isparseable()Source.putaround()Source.compile()_pytest._code.compile()_pytest._code.source.getsource()Exits with an error if --basetemp is empty, the current working directory, or a parent directory.
--basetempTestReport.longrepr is now always a ReprExceptionInfo instance, previously a str when a test failed with pytest.fail(..., pytrace=False).
TestReport.longreprReprExceptionInfopytest.failSecurity1
Creates temporary directories under /tmp with private permissions and errors if a pre-existing pytest-of-<username> directory is owned by another user.
tmp_pathtmpdirPlatform1
Adds support for Python 3.10.
Deprecations to plan for
Deprecated10
Directly constructing or calling several private classes and functions is deprecated and now emits a warning.
_pytest.cacheprovider.Cache_pytest.cacheprovider.Cache.for_config()_pytest.cacheprovider.Cache.clear_cache()_pytest.cacheprovider.Cache.cache_dir_from_config()_pytest.capture.CaptureFixture_pytest.fixtures.FixtureRequest_pytest.fixtures.SubRequest_pytest.logging.LogCaptureFixtureThe --strict command-line option is deprecated in favor of --strict-markers.
--strict--strict-markers--strict-configThe @pytest.yield_fixture decorator is deprecated; use pytest.fixture instead.
@pytest.yield_fixturepytest.fixtureDeprecates the pytest.collect module; all its names can be imported from pytest directly.
pytest.collectDeprecates the pytest._fillfuncargs function kept for backward compatibility with an older plugin.
pytest._fillfuncargsfunction._request._fillfixtures()Deprecates the special -k '-expr' and -k 'expr:' syntaxes; use -k 'not expr' instead.
-kDeprecates the pytest_warning_captured hook in favor of pytest_warning_recorded, to be removed in a future version.
pytest_warning_capturedpytest_warning_recordedDeprecates gethookproxy() and isinitpath() methods of FSCollector and Package; use self.session equivalents instead.
FSCollector.gethookproxy()FSCollector.isinitpath()Package.gethookproxy()Package.isinitpath()self.session.gethookproxy()self.session.isinitpath()Deprecates the special -k '-expr' syntax in favor of -k 'not expr', and the special -k 'expr:' syntax.
-kDeprecates the pytest_warning_captured hook in favor of the pytest_warning_recorded hook.
pytest_warning_capturedpytest_warning_recordedAPI changes
Generated by DepDelta from published Python source. Not mixed with prose notes.
- added:
export Cache - added:
export CaptureFixture - added:
export FixtureLookupError - added:
export FixtureRequest - added:
export LogCaptureFixture - added:
export MonkeyPatch - added:
export PytestUnhandledThreadExceptionWarning - added:
export PytestUnraisableExceptionWarning - added:
export Pytester - added:
export TempPathFactory - added:
export TempdirFactory - added:
export Testdir - added:
export WarningsRecorder - added:
export collect - added:
export console_main
- added:
class FakeCollectModule(ModuleType) - added:
constructor FakeCollectModule() -> None - added:
variable COLLECT_FAKEMODULE_ATTRIBUTES