Recent Releases of pytest
pytest - 8.4.1
pytest 8.4.1 (2025-06-17)
Bug fixes
#13461: Corrected
_pytest.terminal.TerminalReporter.isattyto support being called as a method. Before it was just a boolean which could break correct code when using-o log_cli=true).#13477: Reintroduced
pytest.PytestReturnNotNoneWarning{.interpreted-text role="class"} which was removed by accident in pytest [8.4]{.title-ref}.This warning is raised when a test functions returns a value other than
None, which is often a mistake made by beginners.See
return-not-none{.interpreted-text role="ref"} for more information.#13497: Fixed compatibility with
Twisted 25+.
Improved documentation
- #13492: Fixed outdated warning about
faulthandlernot working on Windows.
- Python
Published by github-actions[bot] 8 months ago
pytest - 8.4.0
pytest 8.4.0 (2025-06-02)
Removals and backward incompatible breaking changes
#11372: Async tests will now fail, instead of warning+skipping, if you don\'t have any suitable plugin installed.
#12346: Tests will now fail, instead of raising a warning, if they return any value other than None.
#12874: We dropped support for Python 3.8 following its end of life (2024-10-07).
#12960: Test functions containing a yield now cause an explicit error. They have not been run since pytest 4.0, and were previously marked as an expected failure and deprecation warning.
See
the docs <yield tests deprecated>{.interpreted-text role="ref"} for more information.
Deprecations (removal in next major release)
- #10839: Requesting an asynchronous fixture without a [pytestfixturesetup]{.title-ref} hook that resolves it will now give a DeprecationWarning. This most commonly happens if a sync test requests an async fixture. This should have no effect on a majority of users with async tests or fixtures using async pytest plugins, but may affect non-standard hook setups or
autouse=True. For guidance on how to work around this warning seesync-test-async-fixture{.interpreted-text role="ref"}.
New features
#11538: Added
pytest.RaisesGroup{.interpreted-text role="class"} as an equivalent topytest.raises{.interpreted-text role="func"} for expectingExceptionGroup{.interpreted-text role="exc"}. Also addspytest.RaisesExc{.interpreted-text role="class"} which is now the logic behindpytest.raises{.interpreted-text role="func"} and used as parameter topytest.RaisesGroup{.interpreted-text role="class"}.RaisesGroupincludes the ability to specify multiple different expected exceptions, the structure of nested exception groups, and flags for emulatingexcept* <except_star>{.interpreted-text role="ref"}. Seeassert-matching-exception-groups{.interpreted-text role="ref"} and docstrings for more information.#12081: Added
capteesys{.interpreted-text role="fixture"} to capture AND pass output to next handler set by--capture=.#12504:
pytest.mark.xfail{.interpreted-text role="func"} now acceptspytest.RaisesGroup{.interpreted-text role="class"} for theraisesparameter when you expect an exception group. You can also pass apytest.RaisesExc{.interpreted-text role="class"} if you e.g. want to make use of thecheckparameter.#12713: New [--force-short-summary]{.title-ref} option to force condensed summary output regardless of verbosity level.
This lets users still see condensed summary output of failures for quick reference in log files from job outputs, being especially useful if non-condensed output is very verbose.
#12749: pytest traditionally collects classes/functions in the test module namespace even if they are imported from another file.
For example:
``` python
contents of src/domain.py
class Testament: ...
contents of tests/test_testament.py
from domain import Testament
def test_testament(): ... ```
In this scenario with the default options, pytest will collect the class [Testament]{.title-ref} from [tests/test_testament.py]{.title-ref} because it starts with [Test]{.title-ref}, even though in this case it is a production class being imported in the test module namespace.
This behavior can now be prevented by setting the new
collect_imported_tests{.interpreted-text role="confval"} configuration option tofalse, which will make pytest collect classes/functions from test files only if they are defined in that file.-- by
FreerGit{.interpreted-text role="user"}#12765: Thresholds to trigger snippet truncation can now be set with
truncation_limit_lines{.interpreted-text role="confval"} andtruncation_limit_chars{.interpreted-text role="confval"}.See
truncation-params{.interpreted-text role="ref"} for more information.#13125:
console_output_style{.interpreted-text role="confval"} now supportstimesto show execution time of each test.#13192:
pytest.raises{.interpreted-text role="func"} will now raise a warning when passing an empty string tomatch, as this will match against any value. Usematch="^$"if you want to check that an exception has no message.#13192:
pytest.raises{.interpreted-text role="func"} will now print a helpful string diff if matching fails and the match parameter has^and$and is otherwise escaped.#13192: You can now pass
with pytest.raises(check=fn): <pytest.raises>{.interpreted-text role="func"}, wherefnis a function which takes a raised exception and returns a boolean. Theraisesfails if no exception was raised (as usual), passes if an exception is raised andfnreturnsTrue(as well asmatchand the type matching, if specified, which are checked before), and propagates the exception iffnreturnsFalse(which likely also fails the test).#13228:
hidden-param{.interpreted-text role="ref"} can now be used inidofpytest.param{.interpreted-text role="func"} or inidsofMetafunc.parametrize <pytest.Metafunc.parametrize>{.interpreted-text role="py:func"}. It hides the parameter set from the test name.#13253: New flag:
--disable-plugin-autoload <disable_plugin_autoload>{.interpreted-text role="ref"} which works as an alternative toPYTEST_DISABLE_PLUGIN_AUTOLOAD{.interpreted-text role="envvar"} when setting environment variables is inconvenient; and allows setting it in config files withaddopts{.interpreted-text role="confval"}.
Improvements in existing functionality
#10224: pytest\'s
shortandlongtraceback styles (how-to-modifying-python-tb-printing{.interpreted-text role="ref"}) now have partial657{.interpreted-text role="pep"} support and will show specific code segments in the traceback.``` pytest ================================= FAILURES ================================= _______________________ testgetscorrecttracebacks ______________________
testtracebacks.py:12: in testgetscorrecttracebacks assert manhattandistance(p1, p2) == 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^ testtracebacks.py:6: in manhattandistance return abs(point1.x - point2.x) + abs(point1.y - point_2.y) ^^^^^^^^^ E AttributeError: 'NoneType' object has no attribute 'x' ```
-- by
ammaraskar{.interpreted-text role="user"}#11118: Now
pythonpath{.interpreted-text role="confval"} configures [\$PYTHONPATH]{.title-ref} earlier than before during the initialization process, which now also affects plugins loaded via the [-p]{.title-ref} command-line option.-- by
millerdev{.interpreted-text role="user"}#11381: The
typeparameter of theparser.addinimethod now accepts [\"int\"]{.title-ref} and"float"parameters, facilitating the parsing of configuration values in the configuration file.Example:
python def pytest_addoption(parser): parser.addini("int_value", type="int", default=2, help="my int value") parser.addini("float_value", type="float", default=4.2, help="my float value")The [pytest.ini]{.title-ref} file:
ini [pytest] int_value = 3 float_value = 5.4#11525: Fixtures are now clearly represented in the output as a \"fixture object\", not as a normal function as before, making it easy for beginners to catch mistakes such as referencing a fixture declared in the same module but not requested in the test function.
-- by
the-compiler{.interpreted-text role="user"} andglyphack{.interpreted-text role="user"}#12426: A warning is now issued when
pytest.mark.usefixtures ref{.interpreted-text role="ref"} is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored.#12707: Exception chains can be navigated when dropped into Pdb in Python 3.13+.
#12736: Added a new attribute [name]{.title-ref} with the fixed value [\"pytest tests\"]{.title-ref} to the root tag [testsuites]{.title-ref} of the junit-xml generated by pytest.
This attribute is part of many junit-xml specifications and is even part of the [junit-10.xsd]{.title-ref} specification that pytest\'s implementation is based on.
#12943: If a test fails with an exceptiongroup with a single exception, the contained exception will now be displayed in the short test summary info.
#12958: A number of
unraisable <unraisable>{.interpreted-text role="ref"} enhancements:- Set the unraisable hook as early as possible and unset it as late as possible, to collect the most possible number of unraisable exceptions.
- Call the garbage collector just before unsetting the unraisable hook, to collect any straggling exceptions.
- Collect multiple unraisable exceptions per test phase.
- Report the
tracemalloc{.interpreted-text role="mod"} allocation traceback (if available). - Avoid using a generator based hook to allow handling
StopIteration{.interpreted-text role="class"} in test failures. - Report the unraisable exception as the cause of the
pytest.PytestUnraisableExceptionWarning{.interpreted-text role="class"} exception if raised. - Compute the
reprof the unraisable object in the unraisable hook so you get the latest information if available, and should help with resurrection of the object.
#13010:
pytest.approx{.interpreted-text role="func"} now can compare collections that contain numbers and non-numbers mixed.#13016: A number of
threadexception <unraisable>{.interpreted-text role="ref"} enhancements:- Set the excepthook as early as possible and unset it as late as possible, to collect the most possible number of unhandled exceptions from threads.
- Collect multiple thread exceptions per test phase.
- Report the
tracemalloc{.interpreted-text role="mod"} allocation traceback (if available). - Avoid using a generator based hook to allow handling
StopIteration{.interpreted-text role="class"} in test failures. - Report the thread exception as the cause of the
pytest.PytestUnhandledThreadExceptionWarning{.interpreted-text role="class"} exception if raised. - Extract the
nameof the thread object in the excepthook which should help with resurrection of the thread.
#13031: An empty parameter set as in
pytest.mark.parametrize([], ids=idfunc)will no longer trigger a call toidfuncwith internal objects.#13115: Allows supplying
ExceptionGroup[Exception]andBaseExceptionGroup[BaseException]topytest.raisesto keep full typing onExceptionInfo <pytest.ExceptionInfo>{.interpreted-text role="class"}:python with pytest.raises(ExceptionGroup[Exception]) as exc_info: some_function()Parametrizing with other exception types remains an error - we do not check the types of child exceptions and thus do not permit code that might look like we do.
#13122: The
--stepwisemode received a number of improvements:It no longer forgets the last failed test in case pytest is executed later without the flag.
This enables the following workflow:
1. Execute pytest with `--stepwise`, pytest then stops at the first failing test; 2. Iteratively update the code and run the test in isolation, without the `--stepwise` flag (for example in an IDE), until it is fixed. 3. Execute pytest with `--stepwise` again and pytest will continue from the previously failed test, and if it passes, continue on to the next tests. Previously, at step 3, pytest would start from the beginning, forgetting the previously failed test. This change however might cause issues if the `--stepwise` mode is used far apart in time, as the state might get stale, so the internal state will be reset automatically in case the test suite changes (for now only the number of tests are considered for this, we might change/improve this on the future).- New
--stepwise-reset/--sw-resetflag, allowing the user to explicitly reset the stepwise state and restart the workflow from the beginning.
#13308: Added official support for Python 3.14.
#13380: Fix
ExceptionGroup{.interpreted-text role="class"} traceback filtering to exclude pytest internals.#13415: The author metadata of the BibTex example is now correctly formatted with last names following first names. An example of BibLaTex has been added. BibTex and BibLaTex examples now clearly indicate that what is cited is software.
-- by
willynilly{.interpreted-text role="user"}#13420: Improved test collection performance by optimizing path resolution used in
FSCollector.#13457: The error message about duplicate parametrization no longer displays an internal stack trace.
#4112: Using
pytest.mark.usefixtures <pytest.mark.usefixtures ref>{.interpreted-text role="ref"} onpytest.param{.interpreted-text role="func"} now produces an error instead of silently doing nothing.#5473: Replace [:]{.title-ref} with [;]{.title-ref} in the assertion rewrite warning message so it can be filtered using standard Python warning filters before calling
pytest.main{.interpreted-text role="func"}.#6985: Improved
pytest.approx{.interpreted-text role="func"} to enhance the readability of value ranges and tolerances between 0.001 and 1000.: - The [repr]{.title-ref} method now provides clearer output for values within those ranges, making it easier to interpret the results.
- Previously, the output for those ranges of values and tolerances was displayed in scientific notation (e.g., [42 ± 1.0e+00]{.title-ref}). The updated method now presents the tolerance as a decimal for better readability (e.g., [42 ± 1]{.title-ref}). Example: **Previous Output:** ``` console >>> pytest.approx(42, abs=1) 42 ± 1.0e+00 ``` **Current Output:** ``` console >>> pytest.approx(42, abs=1) 42 ± 1 ``` \-- by `fazeelghafoor`{.interpreted-text role="user"}#7683: The formerly optional
pygmentsdependency is now required, causing output always to be source-highlighted (unless disabled via the--code-highlight=noCLI option).
Bug fixes
#10404: Apply filterwarnings from config/cli as soon as possible, and revert them as late as possible so that warnings as errors are collected throughout the pytest run and before the unraisable and threadexcept hooks are removed.
This allows very late warnings and unraisable/threadexcept exceptions to fail the test suite.
This also changes the warning that the lsof plugin issues from PytestWarning to the new warning PytestFDWarning so it can be more easily filtered.
#11067: The test report is now consistent regardless if the test xfailed via
pytest.mark.xfail <pytest.mark.xfail ref>{.interpreted-text role="ref"} orpytest.fail{.interpreted-text role="func"}.Previously, xfailed tests via the marker would have the string
"reason: "prefixed to the message, while those xfailed via the function did not. The prefix has been removed.#12008: In
11220{.interpreted-text role="pr"}, an unintended change in reordering was introduced by changing the way indices were assigned to direct params. More specifically, before that change, the indices of direct params to metafunc\'s callspecs were assigned after all parametrizations took place. Now, that change is reverted.#12863: Fix applying markers, including
pytest.mark.parametrize <pytest.mark.parametrize ref>{.interpreted-text role="ref"} when placed above [\@staticmethod]{.title-ref} or [\@classmethod]{.title-ref}.#12929: Handle StopIteration from test cases, setup and teardown correctly.
#12938: Fixed
--durations-minargument not respected if-vvis used.#12946: Fixed missing help for
pdb{.interpreted-text role="mod"} commands wrapped by pytest -- byadamchainz{.interpreted-text role="user"}.#12981: Prevent exceptions in
pytest.Config.add_cleanup{.interpreted-text role="func"} callbacks preventing further cleanups.#13047: Restore
pytest.approx{.interpreted-text role="func"} handling of equality checks between [bool]{.title-ref} and [numpy.bool_]{.title-ref} types.Comparing [bool]{.title-ref} and [numpy.bool_]{.title-ref} using
pytest.approx{.interpreted-text role="func"} accidentally changed in version [8.3.4]{.title-ref} and [8.3.5]{.title-ref} to no longer match:``` pycon
import numpy as np from pytest import approx [np.True, np.True] == pytest.approx([True, True]) False ```
This has now been fixed:
``` pycon
[np.True, np.True] == pytest.approx([True, True]) True ```
#13119: Improved handling of invalid regex patterns for filter warnings by providing a clear error message.
#13175: The diff is now also highlighted correctly when comparing two strings.
#13248: Fixed an issue where passing a
scopeinMetafunc.parametrize <pytest.Metafunc.parametrize>{.interpreted-text role="py:func"} withindirect=Truecould result in other fixtures being unable to depend on the parametrized fixture.#13291: Fixed
reprofattrsobjects in assertion failure messages when usingattrs>=25.2.#13312: Fixed a possible
KeyErrorcrash on PyPy during collection of tests involving higher-scoped parameters.#13345: Fix type hints for
pytest.TestReport.when{.interpreted-text role="attr"} andpytest.TestReport.location{.interpreted-text role="attr"}.#13377: Fixed handling of test methods with positional-only parameter syntax.
Now, methods are supported that formally define
selfas positional-only and/or fixture parameters as keyword-only, e.g.:``` python class TestClass:
def test_method(self, /, *, fixture): ...```
Before, this caused an internal error in pytest.
#13384: Fixed an issue where pytest could report negative durations.
#13420: Added
lru_cachetonodes._check_initialpaths_for_relpath.#9037: Honor
disable_test_id_escaping_and_forfeit_all_rights_to_community_support{.interpreted-text role="confval"} when escaping ids in parametrized tests.
Improved documentation
#12535: [This example]{.title-ref}<https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures> showed
printstatements that do not exactly reflect what the different branches actually do. The fix makes the example more precise.#13218: Pointed out in the
pytest.approx{.interpreted-text role="func"} documentation that it considers booleans unequal to numeric zero or one.#13221: Improved grouping of CLI options in the
--helpoutput.#6649: Added
~pytest.TerminalReporter{.interpreted-text role="class"} to theapi-reference{.interpreted-text role="ref"} documentation page.#8612: Add a recipe for handling abstract test classes in the documentation.
A new example has been added to the documentation to demonstrate how to use a mixin class to handle abstract test classes without manually setting the
__test__attribute for subclasses. This ensures that subclasses of abstract test classes are automatically collected by pytest.
Packaging updates and notes for downstreams
- #13317: Specified minimum allowed versions of
colorama,iniconfig, andpackaging; and bumped the minimum allowed version ofexceptiongroupforpython_version<'3.11'from a release candidate to a full release.
Contributor-facing changes
#12017: Mixed internal improvements:
- Migrate formatting to f-strings in some tests.
- Use type-safe constructs in JUnitXML tests.
- Moved
MockTiminginto_pytest.timing.
-- by
RonnyPfannschmidt{.interpreted-text role="user"}#12647: Fixed running the test suite with the
hypothesispytest plugin.
Miscellaneous internal changes
- #6649: Added
~pytest.TerminalReporter{.interpreted-text role="class"} to the public pytest API, as it is part of the signature of thepytest_terminal_summary{.interpreted-text role="hook"} hook.
- Python
Published by github-actions[bot] 9 months ago
pytest - 8.3.5
pytest 8.3.5 (2025-03-02)
Bug fixes
- #11777: Fixed issue where sequences were still being shortened even with
-vvverbosity. - #12888: Fixed broken input when using Python 3.13+ and a
libeditbuild of Python, such as on macOS or with uv-managed Python binaries from thepython-build-standaloneproject. This could manifest e.g. by a broken prompt when usingPdb, or seeing empty inputs with manual usage ofinput()and suspended capturing. - #13026: Fixed
AttributeError{.interpreted-text role="class"} crash when using--import-mode=importlibwhen top-level directory same name as another module of the standard library. - #13053: Fixed a regression in pytest 8.3.4 where, when using
--import-mode=importlib, a directory containing py file with the same name would cause anImportError - #13083: Fixed issue where pytest could crash if one of the collected directories got removed during collection.
Improved documentation
#12842: Added dedicated page about using types with pytest.
See
types{.interpreted-text role="ref"} for detailed usage.
Contributor-facing changes
- #13112: Fixed selftest failures in
test_terminal.pywith Pygments >= 2.19.0 - #13256: Support for Towncier versions released in 2024 has been re-enabled
when building Sphinx docs -- by
webknjaz{.interpreted-text role="user"}.
- Python
Published by github-actions[bot] 12 months ago
pytest - 8.3.4
pytest 8.3.4 (2024-12-01)
Bug fixes
#12592: Fixed
KeyError{.interpreted-text role="class"} crash when using--import-mode=importlibin a directory layout where a directory contains a child directory with the same name.#12818: Assertion rewriting now preserves the source ranges of the original instructions, making it play well with tools that deal with the
AST, like executing.#12849: ANSI escape codes for colored output now handled correctly in
pytest.fail{.interpreted-text role="func"} with [pytrace=False]{.title-ref}.#9353:
pytest.approx{.interpreted-text role="func"} now uses strict equality when given booleans.
Improved documentation
#10558: Fix ambiguous docstring of
pytest.Config.getoption{.interpreted-text role="func"}.#10829: Improve documentation on the current handling of the
--basetempoption and its lack of retention functionality (temporary directory location and retention{.interpreted-text role="ref"}).#12866: Improved cross-references concerning the
recwarn{.interpreted-text role="fixture"} fixture.#12966: Clarify
filterwarnings{.interpreted-text role="ref"} docs on filter precedence/order when using multiple@pytest.mark.filterwarnings <pytest.mark.filterwarnings ref>{.interpreted-text role="ref"} marks.
Contributor-facing changes
- #12497: Fixed two failing pdb-related tests on Python 3.13.
- Python
Published by nicoddemus about 1 year ago
pytest - 8.3.3
pytest 8.3.3 (2024-09-09)
Bug fixes
#12446: Avoid calling
@property(and other instance descriptors) during fixture discovery -- byasottile{.interpreted-text role="user"}#12659: Fixed the issue of not displaying assertion failure differences when using the parameter
--import-mode=importlibin pytest>=8.1.#12667: Fixed a regression where type change in [ExceptionInfo.errisinstance]{.title-ref} caused [mypy]{.title-ref} to fail.
#12744: Fixed typing compatibility with Python 3.9 or less -- replaced [typing.Self]{.title-ref} with [typing_extensions.Self]{.title-ref} -- by
Avasam{.interpreted-text role="user"}#12745: Fixed an issue with backslashes being incorrectly converted in nodeid paths on Windows, ensuring consistent path handling across environments.
#6682: Fixed bug where the verbosity levels where not being respected when printing the \"msg\" part of failed assertion (as in
assert condition, msg).#9422: Fix bug where disabling the terminal plugin via
-p no:terminalwould cause crashes related to missing theverboseoption.-- by
GTowers1{.interpreted-text role="user"}
Improved documentation
- #12663: Clarify that the [pytest_deselected]{.title-ref} hook should be called from [pytest_collection_modifyitems]{.title-ref} hook implementations when items are deselected.
- #12678: Remove erroneous quotes from [tmp_path_retention_policy]{.title-ref} example in docs.
Miscellaneous internal changes
- #12769: Fix typos discovered by codespell and add codespell to pre-commit hooks.
- Python
Published by github-actions[bot] over 1 year ago
pytest - 8.3.0
pytest 8.3.0 (2024-07-20)
New features
#12231: Added [--xfail-tb]{.title-ref} flag, which turns on traceback output for XFAIL results.
- If the [--xfail-tb]{.title-ref} flag is not given, tracebacks for XFAIL results are NOT shown.
- The style of traceback for XFAIL is set with [--tb]{.title-ref}, and can be [auto|long|short|line|native|no]{.title-ref}.
- Note: Even if you have [--xfail-tb]{.title-ref} set, you won\'t see them if [--tb=no]{.title-ref}.
Some history:
With pytest 8.0, [-rx]{.title-ref} or [-ra]{.title-ref} would not only turn on summary reports for xfail, but also report the tracebacks for xfail results. This caused issues with some projects that utilize xfail, but don\'t want to see all of the xfail tracebacks.
This change detaches xfail tracebacks from [-rx]{.title-ref}, and now we turn on xfail tracebacks with [--xfail-tb]{.title-ref}. With this, the default [-rx]{.title-ref}/ [-ra]{.title-ref} behavior is identical to pre-8.0 with respect to xfail tracebacks. While this is a behavior change, it brings default behavior back to pre-8.0.0 behavior, which ultimately was considered the better course of action.
#12281: Added support for keyword matching in marker expressions.
Now tests can be selected by marker keyword arguments. Supported values are
int{.interpreted-text role="class"}, (unescaped)str{.interpreted-text role="class"},bool{.interpreted-text role="class"} &None{.interpreted-text role="data"}.See
marker examples <marker_keyword_expression_example>{.interpreted-text role="ref"} for more information.-- by
lovetheguitar{.interpreted-text role="user"}#12567: Added
--no-fold-skippedcommand line option.If this option is set, then skipped tests in short summary are no longer grouped by reason but all tests are printed individually with their nodeid in the same way as other statuses.
-- by
pbrezina{.interpreted-text role="user"}
Improvements in existing functionality
#12469: The console output now uses the \"third-party plugins\" terminology, replacing the previously established but confusing and outdated reference to
setuptools <setuptools:index>{.interpreted-text role="std:doc"} -- bywebknjaz{.interpreted-text role="user"}.#12544, #12545: Python virtual environment detection was improved by checking for a
pyvenv.cfg{.interpreted-text role="file"} file, ensuring reliable detection on various platforms -- byzachsnickers{.interpreted-text role="user"}.#2871: Do not truncate arguments to functions in output when running with [-vvv]{.title-ref}.
#389: The readability of assertion introspection of bound methods has been enhanced -- by
farbodahm{.interpreted-text role="user"},webknjaz{.interpreted-text role="user"},obestwalter{.interpreted-text role="user"},flub{.interpreted-text role="user"} andglyphack{.interpreted-text role="user"}.Earlier, it was like:
``` console =================================== FAILURES =================================== _____________________________________ test _____________________________________
def test():assert Help().fun() == 2E assert 1 == 2 E + where 1 =
>() E + where > = .fun E + where = Help() example.py:7: AssertionError =========================== 1 failed in 0.03 seconds =========================== ```
And now it\'s like:
``` console =================================== FAILURES =================================== _____________________________________ test _____________________________________
def test():assert Help().fun() == 2E assert 1 == 2 E + where 1 = fun() E + where fun =
.fun E + where = Help() test_local.py:13: AssertionError =========================== 1 failed in 0.03 seconds =========================== ```
#7662: Added timezone information to the testsuite timestamp in the JUnit XML report.
Bug fixes
#11706: Fixed reporting of teardown errors in higher-scoped fixtures when using [--maxfail]{.title-ref} or [--stepwise]{.title-ref}.
Originally added in pytest 8.0.0, but reverted in 8.0.2 due to a regression in pytest-xdist. This regression was fixed in pytest-xdist 3.6.1.
#11797:
pytest.approx{.interpreted-text role="func"} now correctly handlesSequence <collections.abc.Sequence>{.interpreted-text role="class"}-like objects.#12204, #12264: Fixed a regression in pytest 8.0 where tracebacks get longer and longer when multiple tests fail due to a shared higher-scope fixture which raised -- by
bluetech{.interpreted-text role="user"}.Also fixed a similar regression in pytest 5.4 for collectors which raise during setup.
The fix necessitated internal changes which may affect some plugins:
-
FixtureDef.cached_result[2]is now a tuple(exc, tb)instead ofexc. -
SetupState.stackfailures are now a tuple(exc, tb)instead ofexc.
-
#12275: Fixed collection error upon encountering an
abstract <abc>{.interpreted-text role="mod"} class, including abstract [unittest.TestCase]{.title-ref} subclasses.#12328: Fixed a regression in pytest 8.0.0 where package-scoped parameterized items were not correctly reordered to minimize setups/teardowns in some cases.
#12424: Fixed crash with [assert testcase is not None]{.title-ref} assertion failure when re-running unittest tests using plugins like pytest-rerunfailures. Regressed in 8.2.2.
#12472: Fixed a crash when returning category
"error"or"failed"with a custom test status frompytest_report_teststatus{.interpreted-text role="hook"} hook --pbrezina{.interpreted-text role="user"}.#12505: Improved handling of invalid regex patterns in
pytest.raises(match=r'...') <pytest.raises>{.interpreted-text role="func"} by providing a clear error message.#12580: Fixed a crash when using the cache class on Windows and the cache directory was created concurrently.
#6962: Parametrization parameters are now compared using [==]{.title-ref} instead of [is]{.title-ref} ([is]{.title-ref} is still used as a fallback if the parameter does not support [==]{.title-ref}). This fixes use of parameters such as lists, which have a different [id]{.title-ref} but compare equal, causing fixtures to be re-computed instead of being cached.
#7166: Fixed progress percentages (the
[ 87%]at the edge of the screen) sometimes not aligning correctly when running with pytest-xdist-n.
Improved documentation
#12153: Documented using
PYTEST_VERSION{.interpreted-text role="envvar"} to detect if code is running from within a pytest run.#12469: The external plugin mentions in the documentation now avoid mentioning
setuptools entry-points <setuptools:index>{.interpreted-text role="std:doc"} as the concept is much more generic nowadays. Instead, the terminology of \"external\", \"installed\", or \"third-party\" plugins (or packages) replaces that.-- by
webknjaz{.interpreted-text role="user"}#12577: [CI]{.title-ref} and [BUILD_NUMBER]{.title-ref} environment variables role is discribed in the reference doc. They now also appear when doing [pytest -h]{.title-ref} -- by
MarcBresson{.interpreted-text role="user"}.
Contributor-facing changes
#12467: Migrated all internal type-annotations to the python3.10+ style by using the [annotations]{.title-ref} future import.
-- by
RonnyPfannschmidt{.interpreted-text role="user"}#11771, #12557: The PyPy runtime version has been updated to 3.9 from 3.8 that introduced a flaky bug at the garbage collector which was not expected to fix there as the 3.8 is EoL.
-- by
x612skm{.interpreted-text role="user"}#12493: The change log draft preview integration has been refactored to use a third party extension
sphinxcontib-towncrier. The previous in-repo script was putting the change log preview file atdoc/en/_changelog_towncrier_draft.rst{.interpreted-text role="file"}. Said file is no longer ignored in Git and might show up among untracked files in the development environments of the contributors. To address that, the contributors can run the following command that will clean it up:console $ git clean -x -i -- doc/en/_changelog_towncrier_draft.rst-- by
webknjaz{.interpreted-text role="user"}#12498: All the undocumented
toxenvironments now have descriptions. They can be listed in one\'s development environment by invokingtox -avin a terminal.-- by
webknjaz{.interpreted-text role="user"}#12501: The changelog configuration has been updated to introduce more accurate audience-tailored categories. Previously, there was a
trivialchange log fragment type with an unclear and broad meaning. It was removed and we now havecontrib,miscandpackagingin place of it.The new change note types target the readers who are downstream packagers and project contributors. Additionally, the miscellaneous section is kept for unspecified updates that do not fit anywhere else.
-- by
webknjaz{.interpreted-text role="user"}#12502: The UX of the GitHub automation making pull requests to update the plugin list has been updated. Previously, the maintainers had to close the automatically created pull requests and re-open them to trigger the CI runs. From now on, they only need to click the [Ready for review]{.title-ref} button instead.
-- by
webknjaz{.interpreted-text role="user"}#12522: The
:pull:RST role has been replaced with a shorter:pr:due to starting to use the implementation from the third-partysphinx-issues{.interpreted-text role="pypi"} Sphinx extension -- bywebknjaz{.interpreted-text role="user"}.#12531: The coverage reporting configuration has been updated to exclude pytest\'s own tests marked as expected to fail from the coverage report. This has an effect of reducing the influence of flaky tests on the resulting number.
-- by
webknjaz{.interpreted-text role="user"}#12533: The
extlinksSphinx extension is no longer enabled. The:bpo:role it used to declare has been removed with that. BPO itself has migrated to GitHub some years ago and it is possible to link the respective issues by using their GitHub issue numbers and the:issue:role that thesphinx-issuesextension implements.-- by
webknjaz{.interpreted-text role="user"}#12562: Possible typos in using the
:user:RST role is now being linted through the pre-commit tool integration -- bywebknjaz{.interpreted-text role="user"}.
- Python
Published by github-actions[bot] over 1 year ago
pytest - 8.2.2
pytest 8.2.2 (2024-06-04)
Bug Fixes
- #12355: Fix possible catastrophic performance slowdown on a certain parametrization pattern involving many higher-scoped parameters.
- #12367: Fix a regression in pytest 8.2.0 where unittest class instances (a fresh one is created for each test) were not released promptly on test teardown but only on session teardown.
- #12381: Fix possible \"Directory not empty\" crashes arising from concurent cache dir (
.pytest_cache) creation. Regressed in pytest 8.2.0.
Improved Documentation
- #12290: Updated Sphinx theme to use Furo instead of Flask, enabling Dark mode theme.
- #12356: Added a subsection to the documentation for debugging flaky tests to mention lack of thread safety in pytest as a possible source of flakyness.
- #12363: The documentation webpages now links to a canonical version to reduce outdated documentation in search engine results.
- Python
Published by github-actions[bot] over 1 year ago
pytest - 8.2.1
pytest 8.2.1 (2024-05-19)
Improvements
- #12334: Support for Python 3.13 (beta1 at the time of writing).
Bug Fixes
- #12120: Fix [PermissionError]{.title-ref} crashes arising from directories which are not selected on the command-line.
- #12191: Keyboard interrupts and system exits are now properly handled during the test collection.
- #12300: Fixed handling of \'Function not implemented\' error under squashfuse_ll, which is a different way to say that the mountpoint is read-only.
- #12308: Fix a regression in pytest 8.2.0 where the permissions of automatically-created
.pytest_cachedirectories becamerwx------instead of the expectedrwxr-xr-x.
Trivial/Internal Changes
- #12333: pytest releases are now attested using the recent Artifact Attestation support from GitHub, allowing users to verify the provenance of pytest\'s sdist and wheel artifacts.
- Python
Published by github-actions[bot] almost 2 years ago
pytest - 8.2.0
pytest 8.2.0 (2024-04-27)
Deprecations
#12069: A deprecation warning is now raised when implementations of one of the following hooks request a deprecated
py.path.localparameter instead of thepathlib.Pathparameter which replaced it:-
pytest_ignore_collect{.interpreted-text role="hook"} - thepathparameter - usecollection_pathinstead. -
pytest_collect_file{.interpreted-text role="hook"} - thepathparameter - usefile_pathinstead. -
pytest_pycollect_makemodule{.interpreted-text role="hook"} - thepathparameter - usemodule_pathinstead. -
pytest_report_header{.interpreted-text role="hook"} - thestartdirparameter - usestart_pathinstead. -
pytest_report_collectionfinish{.interpreted-text role="hook"} - thestartdirparameter - usestart_pathinstead.
The replacement parameters are available since pytest 7.0.0. The old parameters will be removed in pytest 9.0.0.
See
legacy-path-hooks-deprecated{.interpreted-text role="ref"} for more details.-
Features
#11871: Added support for reading command line arguments from a file using the prefix character
@, like e.g.:pytest @tests.txt. The file must have one argument per line.See
Read arguments from file <args-from-file>{.interpreted-text role="ref"} for details.
Improvements
#11523:
pytest.importorskip{.interpreted-text role="func"} will now issue a warning if the module could be found, but raisedImportError{.interpreted-text role="class"} instead ofModuleNotFoundError{.interpreted-text role="class"}.The warning can be suppressed by passing
exc_type=ImportErrortopytest.importorskip{.interpreted-text role="func"}.See
import-or-skip-import-error{.interpreted-text role="ref"} for details.#11728: For
unittest-based tests, exceptions during class cleanup (as raised by functions registered withTestCase.addClassCleanup <unittest.TestCase.addClassCleanup>{.interpreted-text role="meth"}) are now reported instead of silently failing.#11777: Text is no longer truncated in the
short test summary infosection when-vvis given.#12112: Improved namespace packages detection when
consider_namespace_packages{.interpreted-text role="confval"} is enabled, covering more situations (like editable installs).#9502: Added
PYTEST_VERSION{.interpreted-text role="envvar"} environment variable which is defined at the start of the pytest session and undefined afterwards. It contains the value ofpytest.__version__, and among other things can be used to easily check if code is running from within a pytest run.
Bug Fixes
#12065: Fixed a regression in pytest 8.0.0 where test classes containing
setup_methodand tests using@staticmethodor@classmethodwould crash withAttributeError: 'NoneType' object has no attribute 'setup_method'.Now the
request.instance <pytest.FixtureRequest.instance>{.interpreted-text role="attr"} attribute of tests using@staticmethodand@classmethodis no longerNone, but a fresh instance of the class, like in non-static methods. Previously it wasNone, and all fixtures of such tests would share a singleself.#12135: Fixed issue where fixtures adding their finalizer multiple times to fixtures they request would cause unreliable and non-intuitive teardown ordering in some instances.
#12194: Fixed a bug with
--importmode=importliband--doctest-moduleswhere child modules did not appear as attributes in parent modules.#1489: Fixed some instances where teardown of higher-scoped fixtures was not happening in the reverse order they were initialized in.
Trivial/Internal Changes
- #12069:
pluggy>=1.5.0is now required. - #12167:
cache <cache>{.interpreted-text role="ref"}: create supporting files (CACHEDIR.TAG,.gitignore, etc.) in a temporary directory to provide atomic semantics.
- Python
Published by github-actions[bot] almost 2 years ago
pytest - 8.1.1
pytest 8.1.1 (2024-03-08)
::: {.note} ::: {.title} Note :::
This release is not a usual bug fix release -- it contains features and improvements, being a follow up
to 8.1.0, which has been yanked from PyPI.
:::
Features
#11475: Added the new
consider_namespace_packages{.interpreted-text role="confval"} configuration option, defaulting toFalse.If set to
True, pytest will attempt to identify modules that are part of namespace packages when importing modules.#11653: Added the new
verbosity_test_cases{.interpreted-text role="confval"} configuration option for fine-grained control of test execution verbosity. SeeFine-grained verbosity <pytest.fine_grained_verbosity>{.interpreted-text role="ref"} for more details.
Improvements
#10865:
pytest.warns{.interpreted-text role="func"} now validates thatwarnings.warn{.interpreted-text role="func"} was called with a [str]{.title-ref} or a [Warning]{.title-ref}. Currently in Python it is possible to use other types, however this causes an exception whenwarnings.filterwarnings{.interpreted-text role="func"} is used to filter those warnings (see CPython #103577 for a discussion). While this can be considered a bug in CPython, we decided to put guards in pytest as the error message produced without this check in place is confusing.#11311: When using
--override-inifor paths in invocations without a configuration file defined, the current working directory is used as the relative directory.Previoulsy this would raise an
AssertionError{.interpreted-text role="class"}.#11475:
--import-mode=importlib <import-mode-importlib>{.interpreted-text role="ref"} now tries to import modules using the standard import mechanism (but still without changing :pysys.path{.interpreted-text role="data"}), falling back to importing modules directly only if that fails.This means that installed packages will be imported under their canonical name if possible first, for example
app.core.models, instead of having the module name always be derived from their path (for example.env310.lib.site_packages.app.core.models).#11801: Added the
iter_parents() <_pytest.nodes.Node.iter_parents>{.interpreted-text role="func"} helper method on nodes. It is similar tolistchain <_pytest.nodes.Node.listchain>{.interpreted-text role="func"}, but goes from bottom to top, and returns an iterator, not a list.#11850: Added support for
sys.last_exc{.interpreted-text role="data"} for post-mortem debugging on Python>=3.12.#11962: In case no other suitable candidates for configuration file are found, a
pyproject.toml(even without a[tool.pytest.ini_options]table) will be considered as the configuration file and define therootdir.#11978: Add
--log-file-modeoption to the logging plugin, enabling appending to log-files. This option accepts either"w"or"a"and defaults to"w".Previously, the mode was hard-coded to be
"w"which truncates the file before logging.#12047: When multiple finalizers of a fixture raise an exception, now all exceptions are reported as an exception group. Previously, only the first exception was reported.
Bug Fixes
#11475: Fixed regression where
--importmode=importlibwould import non-test modules more than once.#11904: Fixed a regression in pytest 8.0.0 that would cause test collection to fail due to permission errors when using
--pyargs.This change improves the collection tree for tests specified using
--pyargs, see12043{.interpreted-text role="pull"} for a comparison with pytest 8.0 and <8.#12011: Fixed a regression in 8.0.1 whereby
setup_modulexunit-style fixtures are not executed when--doctest-modulesis passed.#12014: Fix the
stacklevelused when warning about marks used on fixtures.#12039: Fixed a regression in
8.0.2where tests created usingtmp_path{.interpreted-text role="fixture"} have been collected multiple times in CI under Windows.
Improved Documentation
- #11790: Documented the retention of temporary directories created using the
tmp_pathfixture in more detail.
Trivial/Internal Changes
#11785: Some changes were made to private functions which may affect plugins which access them:
-
FixtureManager._getautousenames()now takes aNodeitself instead of the nodeid. -
FixtureManager.getfixturedefs()now takes theNodeitself instead of the nodeid. - The
_pytest.nodes.iterparentnodeids()function is removed without replacement. Prefer to traverse the node hierarchy itself instead. If you really need to, copy the function from the previous pytest release.
-
#12069: Delayed the deprecation of the following features to
9.0.0:-
node-ctor-fspath-deprecation{.interpreted-text role="ref"}. -
legacy-path-hooks-deprecated{.interpreted-text role="ref"}.
It was discovered after
8.1.0was released that the warnings about the impeding removal were not being displayed, so the team decided to revert the removal.This is the reason for
8.1.0being yanked.-
pytest 8.1.0 (YANKED)
::: {.note} ::: {.title} Note :::
This release has been yanked: it broke some plugins without the proper warning period, due to some warnings not showing up as expected.
See #12069. :::
- Python
Published by github-actions[bot] almost 2 years ago
pytest - 8.1.0
pytest 8.1.0 (YANKED)
[!IMPORTANT]
This release has been yanked: it broke some plugins without the proper warning period, due to some warnings not showing up as expected. See #12069.
Features
#11475: Added the new
consider_namespace_packages{.interpreted-text role="confval"} configuration option, defaulting toFalse.If set to
True, pytest will attempt to identify modules that are part of namespace packages when importing modules.#11653: Added the new
verbosity_test_cases{.interpreted-text role="confval"} configuration option for fine-grained control of test execution verbosity. SeeFine-grained verbosity <pytest.fine_grained_verbosity>{.interpreted-text role="ref"} for more details.
Improvements
#10865:
pytest.warns{.interpreted-text role="func"} now validates thatwarnings.warn{.interpreted-text role="func"} was called with a [str]{.title-ref} or a [Warning]{.title-ref}. Currently in Python it is possible to use other types, however this causes an exception whenwarnings.filterwarnings{.interpreted-text role="func"} is used to filter those warnings (see CPython #103577 for a discussion). While this can be considered a bug in CPython, we decided to put guards in pytest as the error message produced without this check in place is confusing.#11311: When using
--override-inifor paths in invocations without a configuration file defined, the current working directory is used as the relative directory.Previoulsy this would raise an
AssertionError{.interpreted-text role="class"}.#11475:
--import-mode=importlib <import-mode-importlib>{.interpreted-text role="ref"} now tries to import modules using the standard import mechanism (but still without changing :pysys.path{.interpreted-text role="data"}), falling back to importing modules directly only if that fails.This means that installed packages will be imported under their canonical name if possible first, for example
app.core.models, instead of having the module name always be derived from their path (for example.env310.lib.site_packages.app.core.models).#11801: Added the
iter_parents() <_pytest.nodes.Node.iter_parents>{.interpreted-text role="func"} helper method on nodes. It is similar tolistchain <_pytest.nodes.Node.listchain>{.interpreted-text role="func"}, but goes from bottom to top, and returns an iterator, not a list.#11850: Added support for
sys.last_exc{.interpreted-text role="data"} for post-mortem debugging on Python>=3.12.#11962: In case no other suitable candidates for configuration file are found, a
pyproject.toml(even without a[tool.pytest.ini_options]table) will be considered as the configuration file and define therootdir.#11978: Add
--log-file-modeoption to the logging plugin, enabling appending to log-files. This option accepts either"w"or"a"and defaults to"w".Previously, the mode was hard-coded to be
"w"which truncates the file before logging.#12047: When multiple finalizers of a fixture raise an exception, now all exceptions are reported as an exception group. Previously, only the first exception was reported.
Bug Fixes
#11904: Fixed a regression in pytest 8.0.0 that would cause test collection to fail due to permission errors when using
--pyargs.This change improves the collection tree for tests specified using
--pyargs, see12043{.interpreted-text role="pull"} for a comparison with pytest 8.0 and <8.#12011: Fixed a regression in 8.0.1 whereby
setup_modulexunit-style fixtures are not executed when--doctest-modulesis passed.#12014: Fix the
stacklevelused when warning about marks used on fixtures.#12039: Fixed a regression in
8.0.2where tests created usingtmp_path{.interpreted-text role="fixture"} have been collected multiple times in CI under Windows.
Improved Documentation
- #11790: Documented the retention of temporary directories created using the
tmp_pathfixture in more detail.
Trivial/Internal Changes
- #11785: Some changes were made to private functions which may affect plugins which access them:
-
FixtureManager._getautousenames()now takes aNodeitself instead of the nodeid. -
FixtureManager.getfixturedefs()now takes theNodeitself instead of the nodeid. - The
_pytest.nodes.iterparentnodeids()function is removed without replacement. Prefer to traverse the node hierarchy itself instead. If you really need to, copy the function from the previous pytest release.
-
- Python
Published by github-actions[bot] almost 2 years ago
pytest - 8.0.2
pytest 8.0.2 (2024-02-24)
Bug Fixes
- #11895: Fix collection on Windows where initial paths contain the short version of a path (for example
c:\PROGRA~1\tests). - #11953: Fix an
IndexErrorcrash raising fromgetstatementrange_ast. - #12021: Reverted a fix to [--maxfail]{.title-ref} handling in pytest 8.0.0 because it caused a regression in pytest-xdist whereby session fixture teardowns may get executed multiple times when the max-fails is reached.
- Python
Published by github-actions[bot] about 2 years ago
pytest - 8.0.1
pytest 8.0.1 (2024-02-16)
Bug Fixes
- #11875: Correctly handle errors from
getpass.getuser{.interpreted-text role="func"} in Python 3.13. - #11879: Fix an edge case where
ExceptionInfo._stringify_exceptioncould crashpytest.raises{.interpreted-text role="func"}. - #11906: Fix regression with
pytest.warns{.interpreted-text role="func"} using custom warning subclasses which have more than one parameter in their [__init__]{.title-ref}. - #11907: Fix a regression in pytest 8.0.0 whereby calling
pytest.skip{.interpreted-text role="func"} and similar control-flow exceptions within apytest.warns(){.interpreted-text role="func"} block would get suppressed instead of propagating. - #11929: Fix a regression in pytest 8.0.0 whereby autouse fixtures defined in a module get ignored by the doctests in the module.
- #11937: Fix a regression in pytest 8.0.0 whereby items would be collected in reverse order in some circumstances.
- Python
Published by github-actions[bot] about 2 years ago
pytest - pytest 8.0.0 (2024-01-27)
See 8.0.0rc1 and 8.0.0rc2 for the full changes since pytest 7.4!
Bug Fixes
- #11842: Properly escape the
reasonof askip <pytest.mark.skip ref>{.interpreted-text role="ref"} mark when writing JUnit XML files. - #11861: Avoid microsecond exceeds
1_000_000when usinglog-date-formatwith%fspecifier, which might cause the test suite to crash.
- Python
Published by bluetech about 2 years ago
pytest - 8.0.0rc2
pytest 8.0.0rc2 (2024-01-17)
Improvements
- #11233: Improvements to
-rfor xfailures and xpasses:- Report tracebacks for xfailures when
-rxis set. - Report captured output for xpasses when
-rXis set. - For xpasses, add
-in summary between test name and reason, to match how xfail is displayed.
- Report tracebacks for xfailures when
- #11825: The
pytest_plugin_registered{.interpreted-text role="hook"} hook has a newplugin_nameparameter containing the name by whichpluginis registered.
Bug Fixes
#11706: Fix reporting of teardown errors in higher-scoped fixtures when using [--maxfail]{.title-ref} or [--stepwise]{.title-ref}.
#11758: Fixed
IndexError: string index out of rangecrash inif highlighted[-1] == "\n" and source[-1] != "\n". This bug was introduced in pytest 8.0.0rc1.#9765, #11816: Fixed a frustrating bug that afflicted some users with the only error being
assert mod not in mods. The issue was caused by the fact thatstr(Path(mod))andmod.__file__don\'t necessarily produce the same string, and was being erroneously used interchangably in some places in the code.This fix also broke the internal API of
PytestPluginManager.consider_conftestby introducing a new parameter -- we mention this in case it is being used by external code, even if marked as private.
- Python
Published by github-actions[bot] about 2 years ago
pytest - pytest 8.0.0rc1 (2023-12-30)
See https://docs.pytest.org/en/latest/changelog.html#pytest-8-0-0rc1-2023-12-30 for the rendered changelog.
Breaking Changes
Old Deprecations Are Now Errors
#7363: PytestRemovedIn8Warning deprecation warnings are now errors by default.
Following our plan to remove deprecated features with as little disruption as possible, all warnings of type
PytestRemovedIn8Warningnow generate errors instead of warning messages by default.The affected features will be effectively removed in pytest 8.1, so please consult the
deprecations{.interpreted-text role="ref"} section in the docs for directions on how to update existing code.In the pytest
8.0.Xseries, it is possible to change the errors back into warnings as a stopgap measure by adding this to yourpytest.inifile:ini [pytest] filterwarnings = ignore::pytest.PytestRemovedIn8WarningBut this will stop working when pytest
8.1is released.If you have concerns about the removal of a specific feature, please add a comment to
7363{.interpreted-text role="issue"}.
Version Compatibility
- #11151: Dropped support for Python 3.7, which reached end-of-life on 2023-06-27.
-
pluggy>=1.3.0is now required.
Collection Changes
In this version we\'ve made several breaking changes to pytest\'s collection phase, particularly around how filesystem directories and Python packages are collected, fixing deficiencies and allowing for cleanups and improvements to pytest\'s internals. A deprecation period for these changes was not possible.
#7777: Files and directories are now collected in alphabetical order jointly, unless changed by a plugin. Previously, files were collected before directories. See below for an example.
#8976: Running [pytest pkg/__init__.py]{.title-ref} now collects the [pkg/__init__.py]{.title-ref} file (module) only. Previously, it collected the entire [pkg]{.title-ref} package, including other test files in the directory, but excluding tests in the [__init__.py]{.title-ref} file itself (unless
python_files{.interpreted-text role="confval"} was changed to allow [__init__.py]{.title-ref} file).To collect the entire package, specify just the directory: [pytest pkg]{.title-ref}.
#11137:
pytest.Package{.interpreted-text role="class"} is no longer apytest.Module{.interpreted-text role="class"} orpytest.File{.interpreted-text role="class"}.The
Packagecollector node designates a Python package, that is, a directory with an [__init__.py]{.title-ref} file. PreviouslyPackagewas a subtype ofpytest.Module(which represents a single Python module), the module being the [__init__.py]{.title-ref} file. This has been deemed a design mistake (see11137{.interpreted-text role="issue"} and7777{.interpreted-text role="issue"} for details).The
pathproperty ofPackagenodes now points to the package directory instead of the__init__.pyfile.Note that a
Modulenode for__init__.py(which is not aPackage) may still exist, if it is picked up during collection (e.g. if you configuredpython_files{.interpreted-text role="confval"} to include__init__.pyfiles).#7777: Added a new
pytest.Directory{.interpreted-text role="class"} base collection node, which all collector nodes for filesystem directories are expected to subclass. This is analogous to the existingpytest.File{.interpreted-text role="class"} for file nodes.Changed
pytest.Package{.interpreted-text role="class"} to be a subclass ofpytest.Directory{.interpreted-text role="class"}. APackagerepresents a filesystem directory which is a Python package, i.e. contains an__init__.pyfile.pytest.Package{.interpreted-text role="class"} now only collects files in its own directory; previously it collected recursively. Sub-directories are collected as their own collector nodes, which then collect themselves, thus creating a collection tree which mirrors the filesystem hierarchy.Added a new
pytest.Dir{.interpreted-text role="class"} concrete collection node, a subclass ofpytest.Directory{.interpreted-text role="class"}. This node represents a filesystem directory, which is not apytest.Package{.interpreted-text role="class"}, that is, does not contain an__init__.pyfile. Similarly toPackage, it only collects the files in its own directory.pytest.Session{.interpreted-text role="class"} now only collects the initial arguments, without recursing into directories. This work is now done by therecursive expansion process <pytest.Collector.collect>{.interpreted-text role="func"} of directory collector nodes.session.name <pytest.Session.name>{.interpreted-text role="attr"} is now""; previously it was the rootdir directory name. This matchessession.nodeid <_pytest.nodes.Node.nodeid>{.interpreted-text role="attr"} which has always been [\"\"]{.title-ref}.The collection tree now contains directories/packages up to the
rootdir <rootdir>{.interpreted-text role="ref"}, for initial arguments that are found within the rootdir. For files outside the rootdir, only the immediate directory/package is collected --note however that collecting from outside the rootdir is discouraged.As an example, given the following filesystem tree:
myroot/ pytest.ini top/ ├── aaa │ └── test_aaa.py ├── test_a.py ├── test_b │ ├── __init__.py │ └── test_b.py ├── test_c.py └── zzz ├── __init__.py └── test_zzz.pythe collection tree, as shown by [pytest --collect-only top/]{.title-ref} but with the otherwise-hidden
~pytest.Session{.interpreted-text role="class"} node added for clarity, is now the following:<Session> <Dir myroot> <Dir top> <Dir aaa> <Module test_aaa.py> <Function test_it> <Module test_a.py> <Function test_it> <Package test_b> <Module test_b.py> <Function test_it> <Module test_c.py> <Function test_it> <Package zzz> <Module test_zzz.py> <Function test_it>Previously, it was:
<Session> <Module top/test_a.py> <Function test_it> <Module top/test_c.py> <Function test_it> <Module top/aaa/test_aaa.py> <Function test_it> <Package test_b> <Module test_b.py> <Function test_it> <Package zzz> <Module test_zzz.py> <Function test_it>Code/plugins which rely on a specific shape of the collection tree might need to update.
#11676: The classes
~_pytest.nodes.Node{.interpreted-text role="class"},~pytest.Collector{.interpreted-text role="class"},~pytest.Item{.interpreted-text role="class"},~pytest.File{.interpreted-text role="class"},~_pytest.nodes.FSCollector{.interpreted-text role="class"} are now marked abstract (seeabc{.interpreted-text role="mod"}).We do not expect this change to affect users and plugin authors, it will only cause errors when the code is already wrong or problematic.
Other breaking changes
These are breaking changes where deprecation was not possible.
#11282: Sanitized the handling of the
defaultparameter when defining configuration options.Previously if
defaultwas not supplied forparser.addini <pytest.Parser.addini>{.interpreted-text role="meth"} and the configuration option value was not defined in a test session, then calls toconfig.getini <pytest.Config.getini>{.interpreted-text role="func"} returned an empty list or an empty string depending on whethertypewas supplied or not respectively, which is clearly incorrect. Also,Nonewas not honored even ifdefault=Nonewas used explicitly while defining the option.Now the behavior of
parser.addini <pytest.Parser.addini>{.interpreted-text role="meth"} is as follows:- If
defaultis NOT passed buttypeis provided, then a type-specific default will be returned. For exampletype=boolwill returnFalse,type=strwill return"", etc. - If
default=Noneis passed and the option is not defined in a test session, thenNonewill be returned, regardless of thetype. - If neither
defaultnortypeare provided, assumetype=strand return""as default (this is as per previous behavior).
The team decided to not introduce a deprecation period for this change, as doing so would be complicated both in terms of communicating this to the community as well as implementing it, and also because the team believes this change should not break existing plugins except in rare cases.
- If
#11667: pytest\'s
setup.pyfile is removed. If you relied on this file, e.g. to install pytest usingsetup.py install, please see Why you shouldn\'t invoke setup.py directly for alternatives.#9288:
~pytest.warns{.interpreted-text role="func"} now re-emits unmatched warnings when the context closes -- previously it would consume all warnings, hiding those that were not matched by the function.While this is a new feature, we announce it as a breaking change because many test suites are configured to error-out on warnings, and will therefore fail on the newly-re-emitted warnings.
Deprecations
#10465: Test functions returning a value other than
Nonewill now issue apytest.PytestWarning{.interpreted-text role="class"} instead ofpytest.PytestRemovedIn8Warning{.interpreted-text role="class"}, meaning this will stay a warning instead of becoming an error in the future.#3664: Applying a mark to a fixture function now issues a warning: marks in fixtures never had any effect, but it is a common user error to apply a mark to a fixture (for example
usefixtures) and expect it to work.This will become an error in pytest 9.0.
Features and Improvements
Improved Diffs
These changes improve the diffs that pytest prints when an assertion fails.
Note that syntax highlighting requires the pygments package.
#11520: The very verbose (
-vv) diff output is now colored as a diff instead of a big chunk of red.Python code in error reports is now syntax-highlighted as Python.
The sections in the error reports are now better separated.
#1531: The very verbose diff (
-vv) for every standard library container type is improved. The indentation is now consistent and the markers are on their own separate lines, which should reduce the diffs shown to users.Previously, the standard Python pretty printer was used to generate the output, which puts opening and closing markers on the same line as the first/last entry, in addition to not having consistent indentation.
#10617: Added more comprehensive set assertion rewrites for comparisons other than equality
==, with the following operations now providing better failure messages:!=,<=,>=,<, and>.
Separate Control For Assertion Verbosity
#11387: Added the new
verbosity_assertions{.interpreted-text role="confval"} configuration option for fine-grained control of failed assertions verbosity.If you\'ve ever wished that pytest always show you full diffs, but without making everything else verbose, this is for you.
See
Fine-grained verbosity <pytest.fine_grained_verbosity>{.interpreted-text role="ref"} for more details.For plugin authors,
config.get_verbosity <pytest.Config.get_verbosity>{.interpreted-text role="attr"} can be used to retrieve the verbosity level for a specific verbosity type.
Additional Support For Exception Groups and __notes__
These changes improve pytest\'s support for exception groups.
#10441: Added
ExceptionInfo.group_contains() <pytest.ExceptionInfo.group_contains>{.interpreted-text role="func"}, an assertion helper that tests if anExceptionGroup{.interpreted-text role="class"} contains a matching exception.See
assert-matching-exception-groups{.interpreted-text role="ref"} for an example.#11227: Allow
pytest.raises{.interpreted-text role="func"}matchargument to match against [PEP-678 <https://peps.python.org/pep-0678/>]{.title-ref}__notes__.
Custom Directory collectors
- #7777: Added a new hook
pytest_collect_directory{.interpreted-text role="hook"}, which is called by filesystem-traversing collector nodes, such aspytest.Session{.interpreted-text role="class"},pytest.Dir{.interpreted-text role="class"} andpytest.Package{.interpreted-text role="class"}, to create a collector node for a sub-directory. It is expected to return a subclass ofpytest.Directory{.interpreted-text role="class"}. This hook allows plugins tocustomize the collection of directories <custom directory collectors>{.interpreted-text role="ref"}.
\"New-style\" Hook Wrappers
#11122: pytest now uses \"new-style\" hook wrappers internally, available since pluggy 1.2.0. See pluggy\'s 1.2.0 changelog and the
updated docs <hookwrapper>{.interpreted-text role="ref"} for details.Plugins which want to use new-style wrappers can do so if they require
pytest>=8.
Other Improvements
- #11216: If a test is skipped from inside an
xunit setup fixture <classic xunit>{.interpreted-text role="ref"}, the test summary now shows the test location instead of the fixture location. - #11314: Logging to a file using the
--log-fileoption will use--log-level,--log-formatand--log-date-formatas fallback if--log-file-level,--log-file-formatand--log-file-date-formatare not provided respectively. - #11610: Added the
LogCaptureFixture.filtering() <pytest.LogCaptureFixture.filtering>{.interpreted-text role="func"} context manager which adds a givenlogging.Filter{.interpreted-text role="class"} object to thecaplog{.interpreted-text role="fixture"} fixture. - #11447:
pytest.deprecated_call{.interpreted-text role="func"} now also considers warnings of typeFutureWarning{.interpreted-text role="class"}. - #11600: Improved the documentation and type signature for
pytest.mark.xfail <pytest.mark.xfail>{.interpreted-text role="func"}\'sconditionparam to useFalseas the default value. - #7469:
~pytest.FixtureDef{.interpreted-text role="class"} is now exported aspytest.FixtureDeffor typing purposes. - #11353: Added typing to
~pytest.PytestPluginManager{.interpreted-text role="class"}.
Bug Fixes
- #10701:
pytest.WarningsRecorder.pop{.interpreted-text role="meth"} will return the most-closely-matched warning in the list, rather than the first warning which is an instance of the requested type. - #11255: Fixed crash on [parametrize(..., scope=\"package\")]{.title-ref} without a package present.
- #11277: Fixed a bug that when there are multiple fixtures for an indirect parameter, the scope of the highest-scope fixture is picked for the parameter set, instead of that of the one with the narrowest scope.
- #11456: Parametrized tests now really do ensure that the ids given to each input are unique - for
example,
a, a, a0now results ina1, a2, a0instead of the previous (buggy)a0, a1, a0. This necessarily means changing nodeids where these were previously colliding, and for readability adds an underscore when non-unique ids end in a number. - #11563: Fixed a crash when using an empty string for the same parametrized value more than once.
- #11712: Fixed handling
NO_COLORandFORCE_COLORto ignore an empty value. - #9036:
pytest.warnsand similar functions now capture warnings when an exception is raised inside awithblock.
Improved Documentation
- #11011: Added a warning about modifying the root logger during tests when using
caplog. - #11065: Use
pytestconfiginstead ofrequest.configin cache example to be consistent with the API documentation.
Trivial/Internal Changes
#11208: The (internal)
FixtureDef.cached_resulttype has changed. Now the third itemcached_result[2], when set, is an exception instance instead of an exception triplet.#11218: (This entry is meant to assist plugins which access private pytest internals to instantiate
FixtureRequestobjects.)~pytest.FixtureRequest{.interpreted-text role="class"} is now an abstract class which can\'t be instantiated directly. A new concreteTopRequestsubclass ofFixtureRequesthas been added for therequestfixture in test functions, as counterpart to the existingSubRequestsubclass for therequestfixture in fixture functions.#11315: The
pytester{.interpreted-text role="fixture"} fixture now uses themonkeypatch{.interpreted-text role="fixture"} fixture to manage the current working directory. If you usepytesterin combination withmonkeypatch.undo() <pytest.MonkeyPatch.undo>{.interpreted-text role="func"}, the CWD might get restored. Usemonkeypatch.context() <pytest.MonkeyPatch.context>{.interpreted-text role="func"} instead.#11333: Corrected the spelling of
Config.ArgsSource.INVOCATION_DIR. The previous spellingINCOVATION_DIRremains as an alias.#11638: Fixed the selftests to pass correctly if
FORCE_COLOR,NO_COLORorPY_COLORSis set in the calling environment.
- Python
Published by bluetech about 2 years ago
pytest - pytest 7.4.4 (2023-12-31)
Bug Fixes
- #11140: Fix non-string constants at the top of file being detected as docstrings on Python>=3.8.
- #11572: Handle an edge case where
sys.stderr{.interpreted-text role="data"} andsys.__stderr__{.interpreted-text role="data"} might already be closed whenfaulthandler{.interpreted-text role="ref"} is tearing down. - #11710: Fixed tracebacks from collection errors not getting pruned.
- #7966: Removed unhelpful error message from assertion rewrite mechanism when exceptions are raised in
__iter__methods. Now they are treated un-iterable instead.
Improved Documentation
- #11091: Updated documentation to refer to hyphenated options: replaced
--junitxmlwith--junit-xmland--collectonlywith--collect-only.
- Python
Published by bluetech about 2 years ago
pytest - pytest 7.4.3 (2023-10-24)
Bug Fixes
#10447: Markers are now considered in the reverse mro order to ensure base class markers are considered first -- this resolves a regression.
#11239: Fixed
:=in asserts impacting unrelated test cases.#11439: Handled an edge case where :data:
sys.stderrmight already be closed when :ref:faulthandleris tearing down.
- Python
Published by nicoddemus over 2 years ago
pytest - pytest 7.4.2 (2023-09-07)
Bug Fixes
#11237: Fix doctest collection of
functools.cached_propertyobjects.#11306: Fixed bug using
--importmode=importlibwhich would cause package__init__.pyfiles to be imported more than once in some cases.#11367: Fixed bug where
user_propertieswhere not being saved in the JUnit XML file if a fixture failed during teardown.#11394: Fixed crash when parsing long command line arguments that might be interpreted as files.
Improved Documentation
- #11391: Improved disclaimer on pytest plugin reference page to better indicate this is an automated, non-curated listing.
- Python
Published by nicoddemus over 2 years ago
pytest - pytest 7.4.1 (2023-09-02)
Bug Fixes
#10337: Fixed bug where fake intermediate modules generated by
--import-mode=importlibwould not include the child modules as attributes of the parent modules.#10702: Fixed error assertion handling in
pytest.approxwhenNoneis an expected or received value when comparing dictionaries.#10811: Fixed issue when using
--import-mode=importlibtogether with--doctest-modulesthat caused modules to be imported more than once, causing problems with modules that have import side effects.
- Python
Published by nicoddemus over 2 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.4.0
pytest 7.4.0 (2023-06-23)
Features
- #10901: Added
ExceptionInfo.from_exception() <pytest.ExceptionInfo.from_exception>{.interpreted-text role="func"}, a simpler way to create an~pytest.ExceptionInfo{.interpreted-text role="class"} from an exception. This can replaceExceptionInfo.from_exc_info() <pytest.ExceptionInfo.from_exc_info()>{.interpreted-text role="func"} for most uses.
Improvements
#10872: Update test log report annotation to named tuple and fixed inconsistency in docs for
pytest_report_teststatus{.interpreted-text role="hook"} hook.#10907: When an exception traceback to be displayed is completely filtered out (by mechanisms such as
__tracebackhide__, internal frames, and similar), now only the exception string and the following message are shown:\"All traceback entries are hidden. Pass [--full-trace]{.title-ref} to see hidden and internal frames.\".
Previously, the last frame of the traceback was shown, even though it was hidden.
#10940: Improved verbose output (
-vv) ofskipandxfailreasons by performing text wrapping while leaving a clear margin for progress output.Added
TerminalReporter.wrap_write()as a helper for that.#10991: Added handling of
%fdirective to print microseconds in log format options, such aslog-date-format.#11005: Added the underlying exception to the cache provider\'s path creation and write warning messages.
#11013: Added warning when
testpaths{.interpreted-text role="confval"} is set, but paths are not found by glob. In this case, pytest will fall back to searching from the current directory.#11043: When [--confcutdir]{.title-ref} is not specified, and there is no config file present, the conftest cutoff directory ([--confcutdir]{.title-ref}) is now set to the
rootdir <rootdir>{.interpreted-text role="ref"}. Previously in such cases, [conftest.py]{.title-ref} files would be probed all the way to the root directory of the filesystem. If you are badly affected by this change, consider adding an empty config file to your desired cutoff directory, or explicitly set [--confcutdir]{.title-ref}.#11081: The
norecursedirs{.interpreted-text role="confval"} check is now performed in apytest_ignore_collect{.interpreted-text role="hook"} implementation, so plugins can affect it.If after updating to this version you see that your [norecursedirs]{.title-ref} setting is not being respected, it means that a conftest or a plugin you use has a bad [pytest_ignore_collect]{.title-ref} implementation. Most likely, your hook returns [False]{.title-ref} for paths it does not want to ignore, which ends the processing and doesn\'t allow other plugins, including pytest itself, to ignore the path. The fix is to return [None]{.title-ref} instead of [False]{.title-ref} for paths your hook doesn\'t want to ignore.
#8711:
caplog.set_level() <pytest.LogCaptureFixture.set_level>{.interpreted-text role="func"} andcaplog.at_level() <pytest.LogCaptureFixture.at_level>{.interpreted-text role="func"} will temporarily enable the requestedleveliflevelwas disabled globally vialogging.disable(LEVEL).
Bug Fixes
- #10831: Terminal Reporting: Fixed bug when running in
--tb=linemode wherepytest.fail(pytrace=False)tests reportNone. - #11068: Fixed the
--last-failedwhole-file skipping functionality (\"skipped N files\") fornon-python test files <non-python tests>{.interpreted-text role="ref"}. - #11104: Fixed a regression in pytest 7.3.2 which caused to
testpaths{.interpreted-text role="confval"} to be considered for loading initial conftests, even when it was not utilized (e.g. when explicit paths were given on the command line). Now thetestpathsare only considered when they are in use. - #1904: Fixed traceback entries hidden with
__tracebackhide__ = Truestill being shown for chained exceptions (parts after \"... the above exception ...\" message). - #7781: Fix writing non-encodable text to log file when using
--debug.
Improved Documentation
- #9146: Improved documentation for
caplog.set_level() <pytest.LogCaptureFixture.set_level>{.interpreted-text role="func"}.
Trivial/Internal Changes
- #11031: Enhanced the CLI flag for
-cto now include--config-fileto make it clear that this flag applies to the usage of a custom config file.
- Python
Published by github-actions[bot] over 2 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.3.2
pytest 7.3.2 (2023-06-10)
Bug Fixes
- #10169: Fix bug where very long option names could cause pytest to break with
OSError: [Errno 36] File name too longon some systems. - #10894: Support for Python 3.12 (beta at the time of writing).
- #10987:
testpaths{.interpreted-text role="confval"} is now honored to load rootconftests. - #10999: The [monkeypatch]{.title-ref} [setitem]{.title-ref}/[delitem]{.title-ref} type annotations now allow [TypedDict]{.title-ref} arguments.
- #11028: Fixed bug in assertion rewriting where a variable assigned with the walrus operator could not be used later in a function call.
- #11054: Fixed
--last-failed\'s \"(skipped N files)\" functionality for files inside of packages (directories with [__init__.py]{.title-ref} files).
- Python
Published by github-actions[bot] over 2 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.3.1
pytest 7.3.1 (2023-04-14)
Improvements
- #10875: Python 3.12 support: fixed
RuntimeError: TestResult has no addDuration methodwhen runningunittesttests. - #10890: Python 3.12 support: fixed
shutil.rmtree(onerror=...)deprecation warning when usingtmp_path{.interpreted-text role="fixture"}.
Bug Fixes
- #10896: Fixed performance regression related to
tmp_path{.interpreted-text role="fixture"} and the newtmp_path_retention_policy{.interpreted-text role="confval"} option. - #10903: Fix crash
INTERNALERROR IndexError: list index out of rangewhich happens when displaying an exception where all entries are hidden. This reverts the change \"Correctly handle__tracebackhide__for chained exceptions.\" introduced in version 7.3.0.
- Python
Published by github-actions[bot] almost 3 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.3.0
pytest 7.3.0 (2023-04-08)
Features
- #10525: Test methods decorated with
@classmethodcan now be discovered as tests, following the same rules as normal methods. This fills the gap that static methods were discoverable as tests but not class methods. - #10755:
console_output_style{.interpreted-text role="confval"} now supportsprogress-even-when-capture-noto force the use of the progress output even when capture is disabled. This is useful in large test suites where capture may have significant performance impact. - #7431:
--log-disableCLI option added to disable individual loggers. - #8141: Added
tmp_path_retention_count{.interpreted-text role="confval"} andtmp_path_retention_policy{.interpreted-text role="confval"} configuration options to control how directories created by thetmp_path{.interpreted-text role="fixture"} fixture are kept.
Improvements
- #10226: If multiple errors are raised in teardown, we now re-raise an
ExceptionGroupof them instead of discarding all but the last. - #10658: Allow
-parguments to include spaces (eg:-p no:logginginstead of-pno:logging). Mostly useful in theaddoptssection of the configuration file. - #10710: Added
startandstoptimestamps toTestReportobjects. - #10727: Split the report header for
rootdir,config fileandtestpathsso each has its own line. - #10840: pytest should no longer crash on AST with pathological position attributes, for example testing AST produced by [Hylang <https://github.com/hylang/hy>__]{.title-ref}.
- #6267: The full output of a test is no longer truncated if the truncation message would be longer than the hidden text. The line number shown has also been fixed.
Bug Fixes
- #10743: The assertion rewriting mechanism now works correctly when assertion expressions contain the walrus operator.
- #10765: Fixed
tmp_path{.interpreted-text role="fixture"} fixture always raisingOSError{.interpreted-text role="class"} onemscriptenplatform due to missingos.getuid{.interpreted-text role="func"}. - #1904: Correctly handle
__tracebackhide__for chained exceptions.
Improved Documentation
- #10782: Fixed the minimal example in
goodpractices{.interpreted-text role="ref"}:pip install -e .requires aversionentry inpyproject.tomlto run successfully.
Trivial/Internal Changes
- #10669: pytest no longer depends on the [attrs]{.title-ref} package (don\'t worry, nice diffs for attrs classes are still supported).
- Python
Published by github-actions[bot] almost 3 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.2.2
pytest 7.2.2 (2023-03-03)
Bug Fixes
- #10533: Fixed
pytest.approx{.interpreted-text role="func"} handling of dictionaries containing one or more values of [0.0]{.title-ref}. - #10592: Fixed crash if [--cache-show]{.title-ref} and [--help]{.title-ref} are passed at the same time.
- #10597: Fixed bug where a fixture method named
teardownwould be called as part ofnoseteardown stage. - #10626: Fixed crash if
--fixturesand--helpare passed at the same time. - #10660: Fixed :py
pytest.raises{.interpreted-text role="func"} to return a \'ContextManager\' so that type-checkers could narrowpytest.raises(...) if ... else nullcontext()down to \'ContextManager\' rather than \'object\'.
Improved Documentation
- #10690: Added [CI]{.title-ref} and [BUILD_NUMBER]{.title-ref} environment variables to the documentation.
- #10721: Fixed entry-points declaration in the documentation example using Hatch.
- #10753: Changed wording of the module level skip to be very explicit about not collecting tests and not executing the rest of the module.
- Python
Published by github-actions[bot] almost 3 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.2.1
pytest 7.2.1 (2023-01-13)
Bug Fixes
- #10452: Fix \'importlib.abc.TraversableResources\' deprecation warning in Python 3.12.
- #10457: If a test is skipped from inside a fixture, the test summary now shows the test location instead of the fixture location.
- #10506: Fix bug where sometimes pytest would use the file system root directory as
rootdir <rootdir>{.interpreted-text role="ref"} on Windows. - #10607: Fix a race condition when creating junitxml reports, which could occur when multiple instances of pytest execute in parallel.
- #10641: Fix a race condition when creating or updating the stepwise plugin\'s cache, which could occur when multiple xdist worker nodes try to simultaneously update the stepwise plugin\'s cache.
- Python
Published by github-actions[bot] about 3 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.2.0
pytest 7.2.0 (2022-10-23)
Deprecations
- #10012: Update
pytest.PytestUnhandledCoroutineWarning{.interpreted-text role="class"} to a deprecation; it will raise an error in pytest 8. - #10396: pytest no longer depends on the
pylibrary.pytestprovides a vendored copy ofpy.errorandpy.pathmodules but will use thepylibrary if it is installed. If you need otherpy.*modules, continue to install the deprecatedpylibrary separately, otherwise it can usually be removed as a dependency. #4562: Deprecate configuring hook specs/impls using attributes/marks.
Instead use :py
pytest.hookimpl{.interpreted-text role="func"} and :pypytest.hookspec{.interpreted-text role="func"}. For more details, see thedocs <legacy-path-hooks-deprecated>{.interpreted-text role="ref"}.#9886: The functionality for running tests written for
nosehas been officially deprecated.This includes:
- Plain
setupandteardownfunctions and methods: this might catch users by surprise, assetup()andteardown()are not pytest idioms, but part of thenosesupport. - Setup/teardown using the \@with_setup decorator.
For more details, consult the
deprecation docs <nose-deprecation>{.interpreted-text role="ref"}.- Plain
Features
- #9897: Added shell-style wildcard support to
testpaths.
Improvements
#10218:
@pytest.mark.parametrize()(and similar functions) now accepts anySequence[str]for the argument names, instead of justlist[str]andtuple[str, ...].(Note that
str, which is itself aSequence[str], is still treated as a comma-delimited name list, as before).#10381: The
--no-showlocalsflag has been added. This can be passed directly to tests to override--showlocalsdeclared throughaddopts.#3426: Assertion failures with strings in NFC and NFD forms that normalize to the same string now have a dedicated error message detailing the issue, and their utf-8 representation is expresed instead.
#7337: A warning is now emitted if a test function returns something other than [None]{.title-ref}. This prevents a common mistake among beginners that expect that returning a [bool]{.title-ref} (for example [return foo(a, b) == result]{.title-ref}) would cause a test to pass or fail, instead of using [assert]{.title-ref}.
#8508: Introduce multiline display for warning matching via :py
pytest.warns{.interpreted-text role="func"} and enhance match comparison for :py_pytest._code.ExceptionInfo.match{.interpreted-text role="func"} as returned by :pypytest.raises{.interpreted-text role="func"}.#8646: Improve :py
pytest.raises{.interpreted-text role="func"}. Previously passing an empty tuple would give a confusing error. We now raise immediately with a more helpful message.#9741: On Python 3.11, use the standard library\'s
tomllib{.interpreted-text role="mod"} to parse TOML.tomli{.interpreted-text role="mod"}` is no longer a dependency on Python 3.11.#9742: Display assertion message without escaped newline characters with
-vv.#9823: Improved error message that is shown when no collector is found for a given file.
#9873: Some coloring has been added to the short test summary.
#9883: Normalize the help description of all command-line options.
#9920: Display full crash messages in
short test summary info, when runng in a CI environment.#9987: Added support for hidden configuration file by allowing
.pytest.inias an alternative topytest.ini.
Bug Fixes
- #10150:
sys.stdin{.interpreted-text role="data"} now contains all expected methods of a file-like object when capture is enabled. - #10382: Do not break into pdb when
raise unittest.SkipTest()appears top-level in a file. #7792: Marks are now inherited according to the full MRO in test classes. Previously, if a test class inherited from two or more classes, only marks from the first super-class would apply.
When inheriting marks from super-classes, marks from the sub-classes are now ordered before marks from the super-classes, in MRO order. Previously it was the reverse.
When inheriting marks from super-classes, the [pytestmark]{.title-ref} attribute of the sub-class now only contains the marks directly applied to it. Previously, it also contained marks from its super-classes. Please note that this attribute should not normally be accessed directly; use
pytest.Node.iter_markers{.interpreted-text role="func"} instead.#9159: Showing inner exceptions by forcing native display in
ExceptionGroupseven when using display options other than--tb=native. A temporary step before full implementation of pytest-native display for inner exceptions inExceptionGroups.#9877: Ensure
caplog.get_records(when)returns current/correct data after invokingcaplog.clear().
Improved Documentation
- #10344: Update information on writing plugins to use
pyproject.tomlinstead ofsetup.py. - #9248: The documentation is now built using Sphinx 5.x (up from 3.x previously).
- #9291: Update documentation on how
pytest.warns{.interpreted-text role="func"} affectsDeprecationWarning{.interpreted-text role="class"}.
Trivial/Internal Changes
- #10196:
~pytest.PytestReturnNotNoneWarning{.interpreted-text role="class"} is now a subclass of~pytest.PytestRemovedIn8Warning{.interpreted-text role="class"}: the plan is to make returning non-Nonefrom tests an error in the future. - #10313: Made
_pytest.doctest.DoctestItemexportpytest.DoctestItemfor type check and runtime purposes. Made [_pytest.doctest]{.title-ref} use internal APIs to avoid circular imports. - #9906: Made
_pytest.compatre-exportimportlib_metadatain the eyes of type checkers. - #9910: Fix default encoding warning (
EncodingWarning) incacheprovider - #9984: Improve the error message when we attempt to access a fixture that has been torn down. Add an additional sentence to the docstring explaining when it\'s not a good idea to call getfixturevalue.
- Python
Published by github-actions[bot] over 3 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.1.3
pytest 7.1.3 (2022-08-31)
Bug Fixes
- #10060: When running with
--pdb,TestCase.tearDownis no longer called for tests when the class has been skipped viaunittest.skiporpytest.mark.skip. - #10190: Invalid XML characters in setup or teardown error messages are now properly escaped for JUnit XML reports.
- #10230: Ignore
.pyfiles created bypyproject.toml-based editable builds introduced in pip 21.3. - #3396: Doctests now respect the
--import-modeflag. - #9514: Type-annotate
FixtureRequest.paramasAnyas a stop gap measure until8073{.interpreted-text role="issue"} is fixed. - #9791: Fixed a path handling code in
rewrite.pythat seems to work fine, but was incorrect and fails in some systems. - #9917: Fixed string representation for
pytest.approx{.interpreted-text role="func"} when used to compare tuples.
Improved Documentation
- #9937: Explicit note that
tmpdir{.interpreted-text role="fixture"} fixture is discouraged in favour oftmp_path{.interpreted-text role="fixture"}.
Trivial/Internal Changes
- #10114: Replace atomicwrites dependency on windows with [os.replace]{.title-ref}.
- Python
Published by github-actions[bot] over 3 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.1.2
pytest 7.1.2 (2022-04-23)
Bug Fixes
- #9726: An unnecessary
numpyimport insidepytest.approx{.interpreted-text role="func"} was removed. - #9820: Fix comparison of
dataclasseswithInitVar. - #9869: Increase
stacklevelfor theNODE_CTOR_FSPATH_ARGdeprecation to point to the user\'s code, not pytest. - #9871: Fix a bizarre (and fortunately rare) bug where the [temp_path]{.title-ref} fixture could raise an internal error while attempting to get the current user\'s username.
- Python
Published by github-actions[bot] almost 4 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.1.1
pytest 7.1.1 (2022-03-17)
Bug Fixes
- #9767: Fixed a regression in pytest 7.1.0 where some conftest.py files outside of the source tree (e.g. in the [site-packages]{.title-ref} directory) were not picked up.
- Python
Published by github-actions[bot] almost 4 years ago
pytest - 7.1.0
pytest 7.1.0 (2022-03-13)
Breaking Changes
#8838: As per our policy, the following features have been deprecated in the 6.X series and are now removed:
-
pytest._fillfuncargsfunction. -
pytest_warning_capturedhook - usepytest_warning_recordedinstead. -
-k -foobarsyntax - use-k 'not foobar'instead. -
-k foobar:syntax. -
pytest.collectmodule - import frompytestdirectly.
For more information consult Deprecations and Removals in the docs.
-
#9437: Dropped support for Python 3.6, which reached end-of-life at 2021-12-23.
Improvements
#5192: Fixed test output for some data types where
-vwould show less information.Also, when showing diffs for sequences,
-qwould produce full diffs instead of the expected diff.#9362: pytest now avoids specialized assert formatting when it is detected that the default
__eq__is overridden inattrsordataclasses.#9536: When
-vvis given on command line, show skipping and xfail reasons in full instead of truncating them to fit the terminal width.#9644: More information about the location of resources that led Python to raise
ResourceWarning{.interpreted-text role="class"} can now be obtained by enablingtracemalloc{.interpreted-text role="mod"}.See
resource-warnings{.interpreted-text role="ref"} for more information.#9678: More types are now accepted in the
idsargument to@pytest.mark.parametrize. Previously only [str]{.title-ref}, [float]{.title-ref}, [int]{.title-ref} and [bool]{.title-ref} were accepted; now [bytes]{.title-ref}, [complex]{.title-ref}, [re.Pattern]{.title-ref}, [Enum]{.title-ref} and anything with a [__name__]{.title-ref} are also accepted.#9692:
pytest.approx{.interpreted-text role="func"} now raises aTypeError{.interpreted-text role="class"} when given an unordered sequence (such asset{.interpreted-text role="class"}).Note that this implies that custom classes which only implement
__iter__and__len__are no longer supported as they don\'t guarantee order.
Bug Fixes
- #8242: The deprecation of raising
unittest.SkipTest{.interpreted-text role="class"} to skip collection of tests during the pytest collection phase is reverted - this is now a supported feature again. #9493: Symbolic link components are no longer resolved in conftest paths. This means that if a conftest appears twice in collection tree, using symlinks, it will be executed twice. For example, given
tests/real/conftest.py tests/real/test_it.py tests/link -> tests/real
running
pytest testsnow imports the conftest twice, once astests/real/conftest.pyand once astests/link/conftest.py. This is a fix to match a similar change made to test collection itself in pytest 6.0 (see6523{.interpreted-text role="pull"} for details).#9626: Fixed count of selected tests on terminal collection summary when there were errors or skipped modules.
If there were errors or skipped modules on collection, pytest would mistakenly subtract those from the selected count.
#9645: Fixed regression where
--import-mode=importlibused together withPYTHONPATH{.interpreted-text role="envvar"} orpythonpath{.interpreted-text role="confval"} would cause import errors in test suites.#9708:
pytester{.interpreted-text role="fixture"} now requests amonkeypatch{.interpreted-text role="fixture"} fixture instead of creating one internally. This solves some issues with tests that involve pytest environment variables.#9730: Malformed
pyproject.tomlfiles now produce a clearer error message.
- Python
Published by github-actions[bot] almost 4 years ago
pytest - 7.0.1
pytest 7.0.1 (2022-02-11)
Bug Fixes
- #9608: Fix invalid importing of
importlib.readersin Python 3.9. - #9610: Restore [UnitTestFunction.obj]{.title-ref} to return unbound rather than bound method. Fixes a crash during a failed teardown in unittest TestCases with non-default [__init__]{.title-ref}. Regressed in pytest 7.0.0.
- #9636: The
pythonpathplugin was renamed topython_path. This avoids a conflict with thepytest-pythonpathplugin. - #9642: Fix running tests by id with
::in the parametrize portion. - #9643: Delay issuing a
~pytest.PytestWarning{.interpreted-text role="class"} about diamond inheritance involving~pytest.Item{.interpreted-text role="class"} and~pytest.Collector{.interpreted-text role="class"} so it can be filtered usingstandard warning filters <warnings>{.interpreted-text role="ref"}.
- Python
Published by github-actions[bot] about 4 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.0.0
pytest 7.0.0 (2022-02-03)
(Please see the full set of changes for this release also in the 7.0.0rc1 notes below)
Deprecations
#9488: If custom subclasses of nodes like
pytest.Item{.interpreted-text role="class"} override the__init__method, they should take**kwargs. Seeuncooperative-constructors-deprecated{.interpreted-text role="ref"} for details.Note that a deprection warning is only emitted when there is a conflict in the arguments pytest expected to pass. This deprecation was already part of pytest 7.0.0rc1 but wasn\'t documented.
Bug Fixes
- #9355: Fixed error message prints function decorators when using assert in Python 3.8 and above.
- #9396: Ensure
pytest.Config.inifile{.interpreted-text role="attr"} is available during thepytest_cmdline_main <_pytest.hookspec.pytest_cmdline_main>{.interpreted-text role="func"} hook (regression during7.0.0rc1).
Improved Documentation
- #9404: Added extra documentation on alternatives to common misuses of [pytest.warns(None)]{.title-ref} ahead of its deprecation.
- #9505: Clarify where the configuration files are located. To avoid confusions documentation mentions that configuration file is located in the root of the repository.
Trivial/Internal Changes
- #9521: Add test coverage to assertion rewrite path.
pytest 7.0.0rc1 (2021-12-06)
Breaking Changes
#7259: The
Node.reportinfo() <non-python tests>{.interpreted-text role="ref"} function first return value type has been expanded from [py.path.local | str]{.title-ref} to [os.PathLike[str] | str]{.title-ref}.Most plugins which refer to [reportinfo()]{.title-ref} only define it as part of a custom
pytest.Item{.interpreted-text role="class"} implementation. Since [py.path.local]{.title-ref} is a [os.PathLike[str]]{.title-ref}, these plugins are unaffacted.Plugins and users which call [reportinfo()]{.title-ref}, use the first return value and interact with it as a [py.path.local]{.title-ref}, would need to adjust by calling [py.path.local(fspath)]{.title-ref}. Although preferably, avoid the legacy [py.path.local]{.title-ref} and use [pathlib.Path]{.title-ref}, or use [item.location]{.title-ref} or [item.path]{.title-ref}, instead.
Note: pytest was not able to provide a deprecation period for this change.
#8246:
--versionnow writes version information tostdoutrather thanstderr.#8733: Drop a workaround for pyreadline that made it work with
--pdb.The workaround was introduced in #1281 in 2015, however since then pyreadline seems to have gone unmaintained, is generating warnings, and will stop working on Python 3.10.
#9061: Using
pytest.approx{.interpreted-text role="func"} in a boolean context now raises an error hinting at the proper usage.It is apparently common for users to mistakenly use
pytest.approxlike this:{.sourceCode .python} assert pytest.approx(actual, expected)While the correct usage is:
{.sourceCode .python} assert actual == pytest.approx(expected)The new error message helps catch those mistakes.
#9277: The
pytest.Instancecollector type has been removed. Importingpytest.Instanceor_pytest.python.Instancereturns a dummy type and emits a deprecation warning. Seeinstance-collector-deprecation{.interpreted-text role="ref"} for details.#9308: PytestRemovedIn7Warning deprecation warnings are now errors by default.
Following our plan to remove deprecated features with as little disruption as possible, all warnings of type
PytestRemovedIn7Warningnow generate errors instead of warning messages by default.The affected features will be effectively removed in pytest 7.1, so please consult the
deprecations{.interpreted-text role="ref"} section in the docs for directions on how to update existing code.In the pytest
7.0.Xseries, it is possible to change the errors back into warnings as a stopgap measure by adding this to yourpytest.inifile:{.sourceCode .ini} [pytest] filterwarnings = ignore::pytest.PytestRemovedIn7WarningBut this will stop working when pytest
7.1is released.If you have concerns about the removal of a specific feature, please add a comment to
9308{.interpreted-text role="issue"}.
Deprecations
#7259:
py.path.localarguments for hooks have been deprecated. Seethe deprecation note <legacy-path-hooks-deprecated>{.interpreted-text role="ref"} for full details.py.path.localarguments to Node constructors have been deprecated. Seethe deprecation note <node-ctor-fspath-deprecation>{.interpreted-text role="ref"} for full details.::: {.note} ::: {.admonition-title} Note :::
The name of the
~_pytest.nodes.Node{.interpreted-text role="class"} arguments and attributes (the new attribute beingpath) is the opposite of the situation for hooks (the old argument beingpath).This is an unfortunate artifact due to historical reasons, which should be resolved in future versions as we slowly get rid of the
py{.interpreted-text role="pypi"} dependency (see9283{.interpreted-text role="issue"} for a longer discussion). :::#7469: Directly constructing the following classes is now deprecated:
-
_pytest.mark.structures.Mark -
_pytest.mark.structures.MarkDecorator -
_pytest.mark.structures.MarkGenerator -
_pytest.python.Metafunc -
_pytest.runner.CallInfo -
_pytest._code.ExceptionInfo -
_pytest.config.argparsing.Parser -
_pytest.config.argparsing.OptionGroup -
_pytest.pytester.HookRecorder
These constructors have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 8.
-
#8242: Raising
unittest.SkipTest{.interpreted-text role="class"} to skip collection of tests during the pytest collection phase is deprecated. Usepytest.skip{.interpreted-text role="func"} instead.Note: This deprecation only relates to using
unittest.SkipTest{.interpreted-text role="class"} during test collection. You are probably not doing that. Ordinary usage ofunittest.SkipTest{.interpreted-text role="class"} /unittest.TestCase.skipTest{.interpreted-text role="meth"} /unittest.skip{.interpreted-text role="func"} in unittest test cases is fully supported.#8315: Several behaviors of
Parser.addoption <pytest.Parser.addoption>{.interpreted-text role="meth"} are now scheduled for removal in pytest 8 (deprecated since pytest 2.4.0):-
parser.addoption(..., help=".. %default ..")- use%(default)sinstead. -
parser.addoption(..., type="int/string/float/complex")- usetype=intetc. instead.
-
#8447: Defining a custom pytest node type which is both an
pytest.Item <Item>{.interpreted-text role="class"} and apytest.Collector <Collector>{.interpreted-text role="class"} (e.g.pytest.File <File>{.interpreted-text role="class"}) now issues a warning. It was never sanely supported and triggers hard to debug errors.See
the deprecation note <diamond-inheritance-deprecated>{.interpreted-text role="ref"} for full details.#8592:
pytest_cmdline_preparse{.interpreted-text role="hook"} has been officially deprecated. It will be removed in a future release. Usepytest_load_initial_conftests{.interpreted-text role="hook"} instead.See
the deprecation note <cmdline-preparse-deprecated>{.interpreted-text role="ref"} for full details.#8645:
pytest.warns(None) <pytest.warns>{.interpreted-text role="func"} is now deprecated because many people used it to mean \"this code does not emit warnings\", but it actually had the effect of checking that the code emits at least one warning of any type - likepytest.warns()orpytest.warns(Warning).#8948:
pytest.skip(msg=...) <pytest.skip>{.interpreted-text role="func"},pytest.fail(msg=...) <pytest.fail>{.interpreted-text role="func"} andpytest.exit(msg=...) <pytest.exit>{.interpreted-text role="func"} signatures now accept areasonargument instead ofmsg. Usingmsgstill works, but is deprecated and will be removed in a future release.This was changed for consistency with
pytest.mark.skip <pytest.mark.skip>{.interpreted-text role="func"} andpytest.mark.xfail <pytest.mark.xfail>{.interpreted-text role="func"} which both acceptreasonas an argument.#8174: The following changes have been made to types reachable through
pytest.ExceptionInfo.traceback{.interpreted-text role="attr"}:- The
pathproperty of_pytest.code.CodereturnsPathinstead ofpy.path.local. - The
pathproperty of_pytest.code.TracebackEntryreturnsPathinstead ofpy.path.local.
There was no deprecation period for this change (sorry!).
- The
Features
#5196: Tests are now ordered by definition order in more cases.
In a class hierarchy, tests from base classes are now consistently ordered before tests defined on their subclasses (reverse MRO order).
#7132: Added two environment variables
PYTEST_THEME{.interpreted-text role="envvar"} andPYTEST_THEME_MODE{.interpreted-text role="envvar"} to let the users customize the pygments theme used.#7259: Added
cache.mkdir() <pytest.Cache.mkdir>{.interpreted-text role="meth"}, which is similar to the existingcache.makedir() <pytest.Cache.makedir>{.interpreted-text role="meth"}, but returns apathlib.Path{.interpreted-text role="class"} instead of a legacypy.path.local.Added a
pathstype toparser.addini() <pytest.Parser.addini>{.interpreted-text role="meth"}, as inparser.addini("mypaths", "my paths", type="paths"), which is similar to the existingpathlist, but returns a list ofpathlib.Path{.interpreted-text role="class"} instead of legacypy.path.local.#7469: The types of objects used in pytest\'s API are now exported so they may be used in type annotations.
The newly-exported types are:
-
pytest.ConfigforConfig <pytest.Config>{.interpreted-text role="class"}. -
pytest.Markformarks <pytest.Mark>{.interpreted-text role="class"}. -
pytest.MarkDecoratorformark decorators <pytest.MarkDecorator>{.interpreted-text role="class"}. -
pytest.MarkGeneratorfor thepytest.mark <pytest.MarkGenerator>{.interpreted-text role="class"} singleton. -
pytest.Metafuncfor themetafunc <pytest.MarkGenerator>{.interpreted-text role="class"} argument to thepytest_generate_tests{.interpreted-text role="hook"} hook. -
pytest.CallInfofor theCallInfo <pytest.CallInfo>{.interpreted-text role="class"} type passed to various hooks. -
pytest.PytestPluginManagerforPytestPluginManager <pytest.PytestPluginManager>{.interpreted-text role="class"}. -
pytest.ExceptionInfofor theExceptionInfo <pytest.ExceptionInfo>{.interpreted-text role="class"} type returned frompytest.raises{.interpreted-text role="func"} and passed to various hooks. -
pytest.Parserfor theParser <pytest.Parser>{.interpreted-text role="class"} type passed to thepytest_addoption{.interpreted-text role="hook"} hook. -
pytest.OptionGroupfor theOptionGroup <pytest.OptionGroup>{.interpreted-text role="class"} type returned from theparser.addgroup <pytest.Parser.getgroup>{.interpreted-text role="func"} method. -
pytest.HookRecorderfor theHookRecorder <pytest.HookRecorder>{.interpreted-text role="class"} type returned from~pytest.Pytester{.interpreted-text role="class"}. -
pytest.RecordedHookCallfor theRecordedHookCall <pytest.HookRecorder>{.interpreted-text role="class"} type returned from~pytest.HookRecorder{.interpreted-text role="class"}. -
pytest.RunResultfor theRunResult <pytest.RunResult>{.interpreted-text role="class"} type returned from~pytest.Pytester{.interpreted-text role="class"}. -
pytest.LineMatcherfor theLineMatcher <pytest.RunResult>{.interpreted-text role="class"} type used in~pytest.RunResult{.interpreted-text role="class"} and others. -
pytest.TestReportfor theTestReport <pytest.TestReport>{.interpreted-text role="class"} type used in various hooks. -
pytest.CollectReportfor theCollectReport <pytest.CollectReport>{.interpreted-text role="class"} type used in various hooks.
Constructing most of them directly is not supported; they are only meant for use in type annotations. Doing so will emit a deprecation warning, and may become a hard-error in pytest 8.0.
Subclassing them is also not supported. This is not currently enforced at runtime, but is detected by type-checkers such as mypy.
-
#7856:
--import-mode=importlib <import-modes>{.interpreted-text role="ref"} now works with features that depend on modules being on :pysys.modules{.interpreted-text role="data"}, such aspickle{.interpreted-text role="mod"} anddataclasses{.interpreted-text role="mod"}.#8144: The following hooks now receive an additional
pathlib.Pathargument, equivalent to an existingpy.path.localargument:-
pytest_ignore_collect{.interpreted-text role="hook"} - Thecollection_pathparameter (equivalent to existingpathparameter). -
pytest_collect_file{.interpreted-text role="hook"} - Thefile_pathparameter (equivalent to existingpathparameter). -
pytest_pycollect_makemodule{.interpreted-text role="hook"} - Themodule_pathparameter (equivalent to existingpathparameter). -
pytest_report_header{.interpreted-text role="hook"} - Thestart_pathparameter (equivalent to existingstartdirparameter). -
pytest_report_collectionfinish{.interpreted-text role="hook"} - Thestart_pathparameter (equivalent to existingstartdirparameter).
::: {.note} ::: {.admonition-title} Note :::
The name of the
~_pytest.nodes.Node{.interpreted-text role="class"} arguments and attributes (the new attribute beingpath) is the opposite of the situation for hooks (the old argument beingpath).This is an unfortunate artifact due to historical reasons, which should be resolved in future versions as we slowly get rid of the
py{.interpreted-text role="pypi"} dependency (see9283{.interpreted-text role="issue"} for a longer discussion). :::-
#8251: Implement
Node.pathas apathlib.Path. Both the oldfspathand this new attribute gets set no matter whetherpathorfspath(deprecated) is passed to the constructor. It is a replacement for thefspathattribute (which represents the same path aspy.path.local). Whilefspathis not deprecated yet due to the ongoing migration of methods like~_pytest.Item.reportinfo{.interpreted-text role="meth"}, we expect to deprecate it in a future release.::: {.note} ::: {.admonition-title} Note :::
The name of the
~_pytest.nodes.Node{.interpreted-text role="class"} arguments and attributes (the new attribute beingpath) is the opposite of the situation for hooks (the old argument beingpath).This is an unfortunate artifact due to historical reasons, which should be resolved in future versions as we slowly get rid of the
py{.interpreted-text role="pypi"} dependency (see9283{.interpreted-text role="issue"} for a longer discussion). :::#8421:
pytest.approx{.interpreted-text role="func"} now works on~decimal.Decimal{.interpreted-text role="class"} within mappings/dicts and sequences/lists.#8606: pytest invocations with
--fixtures-per-testand--fixtureshave been enriched with:- Fixture location path printed with the fixture name.
- First section of the fixture\'s docstring printed under the fixture name.
- Whole of fixture\'s docstring printed under the fixture name using
--verboseoption.
#8761: New
version-tuple{.interpreted-text role="ref"} attribute, which makes it simpler for users to do something depending on the pytest version (such as declaring hooks which are introduced in later versions).#8789: Switch TOML parser from
tomltotomlifor TOML v1.0.0 support inpyproject.toml.#8920: Added
pytest.Stash{.interpreted-text role="class"}, a facility for plugins to store their data on~pytest.Config{.interpreted-text role="class"} and~_pytest.nodes.Node{.interpreted-text role="class"}s in a type-safe and conflict-free manner. Seeplugin-stash{.interpreted-text role="ref"} for details.#8953:
RunResult <_pytest.pytester.RunResult>{.interpreted-text role="class"} methodassert_outcomes <_pytest.pytester.RunResult.assert_outcomes>{.interpreted-text role="meth"} now accepts awarningsargument to assert the total number of warnings captured.#8954:
--debugflag now accepts astr{.interpreted-text role="class"} file to route debug logs into, remains defaulted to [pytestdebug.log]{.title-ref}.#9023: Full diffs are now always shown for equality assertions of iterables when [CI]{.title-ref} or
BUILD_NUMBERis found in the environment, even when-visn\'t used.#9113:
RunResult <_pytest.pytester.RunResult>{.interpreted-text role="class"} methodassert_outcomes <_pytest.pytester.RunResult.assert_outcomes>{.interpreted-text role="meth"} now accepts adeselectedargument to assert the total number of deselected tests.#9114: Added
pythonpath{.interpreted-text role="confval"} setting that adds listed paths tosys.path{.interpreted-text role="data"} for the duration of the test session. If you currently use the pytest-pythonpath or pytest-srcpaths plugins, you should be able to replace them with built-in [pythonpath]{.title-ref} setting.
Improvements
#7480: A deprecation scheduled to be removed in a major version X (e.g. pytest 7, 8, 9, ...) now uses warning category [PytestRemovedInXWarning]{.title-ref}, a subclass of
~pytest.PytestDeprecationWarning{.interpreted-text role="class"}, instead ofPytestDeprecationWarning{.interpreted-text role="class"} directly.See
backwards-compatibility{.interpreted-text role="ref"} for more details.#7864: Improved error messages when parsing warning filters.
Previously pytest would show an internal traceback, which besides being ugly sometimes would hide the cause of the problem (for example an
ImportErrorwhile importing a specific warning type).#8335: Improved
pytest.approx{.interpreted-text role="func"} assertion messages for sequences of numbers.The assertion messages now dumps a table with the index and the error of each diff. Example:
> assert [1, 2, 3, 4] == pytest.approx([1, 3, 3, 5]) E assert comparison failed for 2 values: E Index | Obtained | Expected E 1 | 2 | 3 +- 3.0e-06 E 3 | 4 | 5 +- 5.0e-06#8403: By default, pytest will truncate long strings in assert errors so they don\'t clutter the output too much, currently at
240characters by default.However, in some cases the longer output helps, or is even crucial, to diagnose a failure. Using
-vwill now increase the truncation threshold to2400characters, and-vvor higher will disable truncation entirely.#8509: Fixed issue where
unittest.TestCase.setUpClass{.interpreted-text role="meth"} is not called when a test has [/]{.title-ref} in its name since pytest 6.2.0.This refers to the path part in pytest node IDs, e.g.
TestClass::test_itin the node IDtests/test_file.py::TestClass::test_it.Now, instead of assuming that the test name does not contain
/, it is assumed that test path does not contain::. We plan to hopefully make both of these work in the future.#8803: It is now possible to add colors to custom log levels on cli log.
By using
add_color_level <_pytest.logging.add_color_level>{.interpreted-text role="func"} from apytest_configurehook, colors can be added:logging_plugin = config.pluginmanager.get_plugin('logging-plugin') logging_plugin.log_cli_handler.formatter.add_color_level(logging.INFO, 'cyan') logging_plugin.log_cli_handler.formatter.add_color_level(logging.SPAM, 'blue')See
log_colors{.interpreted-text role="ref"} for more information.#8822: When showing fixture paths in [--fixtures]{.title-ref} or [--fixtures-by-test]{.title-ref}, fixtures coming from pytest itself now display an elided path, rather than the full path to the file in the [site-packages]{.title-ref} directory.
#8898: Complex numbers are now treated like floats and integers when generating parameterization IDs.
#9062:
--stepwise-skipnow implicitly enables--stepwiseand can be used on its own.#9205:
pytest.Cache.set{.interpreted-text role="meth"} now preserves key order when saving dicts.
Bug Fixes
- #7124: Fixed an issue where
__main__.pywould raise anImportErrorwhen--doctest-moduleswas provided. - #8061: Fixed failing
staticmethodtest cases if they are inherited from a parent test class. #8192:
testdir.makefilenow silently accepts values which don\'t start with.to maintain backward compatibility with older pytest versions.pytester.makefilenow issues a clearer error if the.is missing in theextargument.#8258: Fixed issue where pytest\'s
faulthandlersupport would not dump traceback on crashes if thefaulthandler{.interpreted-text role="mod"} module was already enabled during pytest startup (usingpython -X dev -m pytestfor example).#8317: Fixed an issue where illegal directory characters derived from
getpass.getuser()raised anOSError.#8367: Fix
Class.from_parentso it forwards extra keyword arguments to the constructor.#8377: The test selection options
pytest -kandpytest -mnow support matching names containing forward slash (/) characters.#8384: The
@pytest.mark.skipdecorator now correctly handles its arguments. When thereasonargument is accidentally given both positional and as a keyword (e.g. because it was confused withskipif), aTypeErrornow occurs. Before, such tests were silently skipped, and the positional argument ignored. Additionally,reasonis now documented correctly as positional or keyword (rather than keyword-only).#8394: Use private names for internal fixtures that handle classic setup/teardown so that they don\'t show up with the default
--fixturesinvocation (but they still show up with--fixtures -v).#8456: The
required_plugins{.interpreted-text role="confval"} config option now works correctly when pre-releases of plugins are installed, rather than falsely claiming that those plugins aren\'t installed at all.#8464:
-c <config file>now also properly definesrootdiras the directory that contains<config file>.#8503:
pytest.MonkeyPatch.syspath_prepend{.interpreted-text role="meth"} no longer fails whensetuptoolsis not installed. It now only callspkg_resources.fixup_namespace_packages{.interpreted-text role="func"} ifpkg_resourceswas previously imported, because it is not needed otherwise.#8548: Introduce fix to handle precision width in
log-cli-formatin turn to fix output coloring for certain formats.#8796: Fixed internal error when skipping doctests.
#8983: The test selection options
pytest -kandpytest -mnow support matching names containing backslash ([\]{.title-ref}) characters. Backslashes are treated literally, not as escape characters (the values being matched against are already escaped).#8990: Fix [pytest -vv]{.title-ref} crashing with an internal exception [AttributeError: \'str\' object has no attribute \'relative_to\']{.title-ref} in some cases.
#9077: Fixed confusing error message when
request.fspath/request.pathwas accessed from a session-scoped fixture.#9163: The end line number and end column offset are now properly set for rewritten assert statements.
#9169: Support for the
filesAPI fromimportlib.resourceswithin rewritten files.#9272: The nose compatibility module-level fixtures [setup()]{.title-ref} and [teardown()]{.title-ref} are now only called once per module, instead of for each test function. They are now called even if object-level [setup]{.title-ref}/[teardown]{.title-ref} is defined.
Improved Documentation
- #4320: Improved docs for [pytester.copy_example]{.title-ref}.
- #5105: Add automatically generated
plugin-list{.interpreted-text role="ref"}. The list is updated on a periodic schedule. - #8337: Recommend numpy.testing module on
pytest.approx{.interpreted-text role="func"} documentation. - #8655: Help text for
--pdbclsmore accurately reflects the option\'s behavior. - #9210: Remove incorrect docs about
confcutdirbeing a configuration option: it can only be set through the--confcutdircommand-line option. - #9242: Upgrade readthedocs configuration to use a newer Ubuntu version` with better unicode support for PDF docs.
- #9341: Various methods commonly used for
non-python tests{.interpreted-text role="ref"} are now correctly documented in the reference docs. They were undocumented previously.
Trivial/Internal Changes
- #8133: Migrate to
setuptools_scm6.x to useSETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTESTfor more robust release tooling. - #8174: The following changes have been made to internal pytest types/functions:
- The
_pytest.code.getfslineno()function returnsPathinstead ofpy.path.local. - The
_pytest.python.path_matches_patterns()function takesPathinstead ofpy.path.local. - The
_pytest._code.Traceback.cut()function accepts anyos.PathLike[str], not justpy.path.local.
- The
- #8248: Internal Restructure: let
python.PyObjMixininherit fromnodes.Nodeto carry over typing information. - #8432: Improve error message when
pytest.skip{.interpreted-text role="func"} is used at module level without passing [allow_module_level=True]{.title-ref}. - #8818: Ensure
regendocopts out ofTOX_ENVcachedir selection to ensure independent example test runs. - #8913: The private
CallSpec2._arg2scopenumattribute has been removed after an internal refactoring. - #8967:
pytest_assertion_pass{.interpreted-text role="hook"} is no longer considered experimental and future changes to it will be considered more carefully. - #9202: Add github action to upload coverage report to codecov instead of bash uploader.
- #9225: Changed the command used to create sdist and wheel artifacts: using the build package instead of setup.py.
- #9351: Correct minor typos in doc/en/example/special.rst.
- Python
Published by github-actions[bot] about 4 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/7.0.0rc1
- Python
Published by github-actions[bot] about 4 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.2.5
pytest 6.2.5 (2021-08-29)
Trivial/Internal Changes
- Python
Published by github-actions[bot] over 4 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.2.4
pytest 6.2.4 (2021-05-04)
Bug Fixes
- #8539: Fixed assertion rewriting on Python 3.10.
- Python
Published by nicoddemus almost 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.2.3
pytest 6.2.3 (2021-04-03)
Bug Fixes
#8414: pytest used to create directories under
/tmpwith world-readable permissions. This means that any user in the system was able to read information written by tests in temporary directories (such as those created by thetmp_path/tmpdirfixture). Now the directories are created with private permissions.pytest used silenty use a pre-existing
/tmp/pytest-of-<username>directory, even if owned by another user. This means another user could pre-create such a directory and gain control of another user\'s temporary directory. Now such a condition results in an error.
- Python
Published by nicoddemus almost 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.2.2
pytest 6.2.2 (2021-01-25)
Bug Fixes
- #8152: Fixed "(<Skipped instance>)" being shown as a skip reason in the verbose test summary line when the reason is empty.
- #8249: Fix the
faulthandlerplugin for occasions when running withtwisted.loggerand usingpytest --capture=no.
- Python
Published by nicoddemus about 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.2.1
pytest 6.2.1 (2020-12-15)
Bug Fixes
- #7678: Fixed bug where
ImportPathMismatchErrorwould be raised for files compiled in the host and loaded later from an UNC mounted path (Windows). #8132: Fixed regression in
approx: in 6.2.0approxno longer raisesTypeErrorwhen dealing with non-numeric types, falling back to normal comparison. Before 6.2.0, array types like tf.DeviceArray fell through to the scalar case, and happened to compare correctly to a scalar if they had only one element. After 6.2.0, these types began failing, because they inherited neither from standard Python number hierarchy nor fromnumpy.ndarray.approxnow converts arguments tonumpy.ndarrayif they expose the array protocol and are not scalars. This treats array-like objects like numpy arrays, regardless of size.
- Python
Published by nicoddemus about 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.2.0
pytest 6.2.0 (2020-12-12)
Breaking Changes
- #7808: pytest now supports python3.6+ only.
Deprecations
#7469: Directly constructing/calling the following classes/functions is now deprecated:
-
_pytest.cacheprovider.Cache -
_pytest.cacheprovider.Cache.for_config() -
_pytest.cacheprovider.Cache.clear_cache() -
_pytest.cacheprovider.Cache.cache_dir_from_config() -
_pytest.capture.CaptureFixture -
_pytest.fixtures.FixtureRequest -
_pytest.fixtures.SubRequest -
_pytest.logging.LogCaptureFixture -
_pytest.pytester.Pytester -
_pytest.pytester.Testdir -
_pytest.recwarn.WarningsRecorder -
_pytest.recwarn.WarningsChecker -
_pytest.tmpdir.TempPathFactory -
_pytest.tmpdir.TempdirFactory
These have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 7.0.0.
-
#7530: The
--strictcommand-line option has been deprecated, use--strict-markersinstead.We have plans to maybe in the future to reintroduce
--strictand make it an encompassing flag for all strictness related options (--strict-markersand--strict-configat the moment, more might be introduced in the future).#7988: The
@pytest.yield_fixturedecorator/function is now deprecated. Use pytest.fixture instead.yield_fixturehas been an alias forfixturefor a very long time, so can be search/replaced safely.
Features
- #5299: pytest now warns about unraisable exceptions and unhandled thread exceptions that occur in tests on Python>=3.8. See unraisable for more information.
#7425: New pytester fixture, which is identical to testdir but its methods return pathlib.Path when appropriate instead of
py.path.local.This is part of the movement to use pathlib.Path objects internally, in order to remove the dependency to
pyin the future.Internally, the old Testdir <_pytest.pytester.Testdir> is now a thin wrapper around Pytester <_pytest.pytester.Pytester>, preserving the old interface.
#7695: A new hook was added, pytest_markeval_namespace which should return a dictionary. This dictionary will be used to augment the "global" variables available to evaluate skipif/xfail/xpass markers.
Pseudo example
conftest.py:{.sourceCode .python} def pytest_markeval_namespace(): return {"color": "red"}test_func.py:{.sourceCode .python} @pytest.mark.skipif("color == 'blue'", reason="Color is not red") def test_func(): assert False#8006: It is now possible to construct a ~pytest.MonkeyPatch object directly as
pytest.MonkeyPatch(), in cases when the monkeypatch fixture cannot be used. Previously some users imported it from the private _pytest.monkeypatch.MonkeyPatch namespace.Additionally, MonkeyPatch.context <pytest.MonkeyPatch.context> is now a classmethod, and can be used as
with MonkeyPatch.context() as mp: .... This is the recommended way to useMonkeyPatchdirectly, since unlike themonkeypatchfixture, an instance created directly is notundo()-ed automatically.
Improvements
- #1265: Added an
__str__implementation to the ~pytest.pytester.LineMatcher class which is returned frompytester.run_pytest().stdoutand similar. It returns the entire output, like the existingstr()method. - #2044: Verbose mode now shows the reason that a test was skipped in the test's terminal line after the "SKIPPED", "XFAIL" or "XPASS".
#7469 The types of builtin pytest fixtures are now exported so they may be used in type annotations of test functions. The newly-exported types are:
-
pytest.FixtureRequestfor the request fixture. -
pytest.Cachefor the cache fixture. -
pytest.CaptureFixture[str]for the capfd and capsys fixtures. -
pytest.CaptureFixture[bytes]for the capfdbinary and capsysbinary fixtures. -
pytest.LogCaptureFixturefor the caplog fixture. -
pytest.Pytesterfor the pytester fixture. -
pytest.Testdirfor the testdir fixture. -
pytest.TempdirFactoryfor the tmpdir_factory fixture. -
pytest.TempPathFactoryfor the tmp_path_factory fixture. -
pytest.MonkeyPatchfor the monkeypatch fixture. -
pytest.WarningsRecorderfor the recwarn fixture.
Constructing them is not supported (except for MonkeyPatch); they are only meant for use in type annotations. Doing so will emit a deprecation warning, and may become a hard-error in pytest 7.0.
Subclassing them is also not supported. This is not currently enforced at runtime, but is detected by type-checkers such as mypy.
-
#7527: When a comparison between namedtuple <collections.namedtuple> instances of the same type fails, pytest now shows the differing field names (possibly nested) instead of their indexes.
#7615: Node.warn <_pytest.nodes.Node.warn> now permits any subclass of Warning, not just PytestWarning <pytest.PytestWarning>.
#7701: Improved reporting when using
--collected-only. It will now show the number of collected tests in the summary stats.#7710: Use strict equality comparison for non-numeric types in pytest.approx instead of raising TypeError.
This was the undocumented behavior before 3.7, but is now officially a supported feature.
#7938: New
--sw-skipargument which is a shorthand for--stepwise-skip.#8023: Added
'node_modules'to default value for norecursedirs.#8032: doClassCleanups <unittest.TestCase.doClassCleanups> (introduced in unittest in Python and 3.8) is now called appropriately.
Bug Fixes
- #4824: Fixed quadratic behavior and improved performance of collection of items using autouse fixtures and xunit fixtures.
- #7758: Fixed an issue where some files in packages are getting lost from
--lfeven though they contain tests that failed. Regressed in pytest 5.4.0. - #7911: Directories created by by tmp_path and tmpdir are now considered stale after 3 days without modification (previous value was 3 hours) to avoid deleting directories still in use in long running test suites.
- #7913: Fixed a crash or hang in pytester.spawn <_pytest.pytester.Pytester.spawn> when the readline module is involved.
- #7951: Fixed handling of recursive symlinks when collecting tests.
- #7981: Fixed symlinked directories not being followed during collection. Regressed in pytest 6.1.0.
- #8016: Fixed only one doctest being collected when using
pytest --doctest-modules path/to/an/__init__.py.
Improved Documentation
- #7429: Add more information and use cases about skipping doctests.
- #7780: Classes which should not be inherited from are now marked
final classin the API reference. - #7872:
_pytest.config.argparsing.Parser.addini()accepts explicitNoneand"string". - #7878: In pull request section, ask to commit after editing changelog and authors file.
Trivial/Internal Changes
- #7802: The
attrsdependency requirement is now >=19.2.0 instead of >=17.4.0. - #8014: .pyc files created by pytest's assertion rewriting now conform to the newer PEP-552 format on Python>=3.7. (These files are internal and only interpreted by pytest itself.)
- Python
Published by nicoddemus about 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.1.2
pytest 6.1.2 (2020-10-28)
Bug Fixes
- #7758: Fixed an issue where some files in packages are getting lost from
--lfeven though they contain tests that failed. Regressed in pytest 5.4.0. - #7911: Directories created by tmpdir are now considered stale after 3 days without modification (previous value was 3 hours) to avoid deleting directories still in use in long running test suites.
Improved Documentation
- #7815: Improve deprecation warning message for
pytest._fillfuncargs().
- Python
Published by nicoddemus over 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.1.1
pytest 6.1.1 (2020-10-03)
Bug Fixes
- #7807: Fixed regression in pytest 6.1.0 causing incorrect rootdir to be determined in some non-trivial cases where parent directories have config files as well.
- #7814: Fixed crash in header reporting when testpaths is used and contains absolute paths (regression in 6.1.0).
- Python
Published by nicoddemus over 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.1.0
pytest 6.1.0 (2020-09-26)
Breaking Changes
#5585: As per our policy, the following features which have been deprecated in the 5.X series are now removed:
- The
funcargnamesread-only property ofFixtureRequest,Metafunc, andFunctionclasses. Usefixturenamesattribute. -
@pytest.fixtureno longer supports positional arguments, pass all arguments by keyword instead. - Direct construction of
Nodesubclasses now raise an error, usefrom_parentinstead. - The default value for
junit_familyhas changed toxunit2. If you require the old format, addjunit_family=xunit1to your configuration file. - The
TerminalReporterno longer has awriterattribute. Plugin authors may use the public functions of theTerminalReporterinstead of accessing theTerminalWriterobject directly. - The
--result-logoption has been removed. Users are recommended to use the pytest-reportlog plugin instead.
For more information consult Deprecations and Removals in the docs.
- The
Deprecations
- #6981: The
pytest.collectmodule is deprecated: all its names can be imported frompytestdirectly. #7097: The
pytest._fillfuncargsfunction is deprecated. This function was kept for backward compatibility with an older plugin.It's functionality is not meant to be used directly, but if you must replace it, use function._request._fillfixtures() instead, though note this is not a public API and may break in the future.
#7210: The special
-k '-expr'syntax to-kis deprecated. Use-k 'not expr'instead.The special
-k 'expr:'syntax to-kis deprecated. Please open an issue if you use this and want a replacement.#7255: The pytest_warning_captured <_pytest.hookspec.pytest_warning_captured> hook is deprecated in favor of pytest_warning_recorded <_pytest.hookspec.pytest_warning_recorded>, and will be removed in a future version.
#7648: The
gethookproxy()andisinitpath()methods ofFSCollectorandPackageare deprecated; useself.session.gethookproxy()andself.session.isinitpath()instead. This should work on all pytest versions.
Features
- #7667: New
--durations-mincommand-line flag controls the minimal duration for inclusion in the slowest list of tests shown by--durations. Previously this was hard-coded to0.005s.
Improvements
#6681: Internal pytest warnings issued during the early stages of initialization are now properly handled and can filtered through filterwarnings or
--pythonwarnings/-W.This also fixes a number of long standing issues: #2891, #7620, #7426.
#7572: When a plugin listed in
required_pluginsis missing or an unknown config key is used with--strict-config, a simple error message is now shown instead of a stacktrace.#7685: Added two new attributes rootpath <_pytest.config.Config.rootpath> and inipath <_pytest.config.Config.inipath> to Config <_pytest.config.Config>. These attributes are pathlib.Path versions of the existing rootdir <_pytest.config.Config.rootdir> and inifile <_pytest.config.Config.inifile> attributes, and should be preferred over them when possible.
#7780: Public classes which are not designed to be inherited from are now marked @final. Code which inherits from these classes will trigger a type-checking (e.g. mypy) error, but will still work in runtime. Currently the
finaldesignation does not appear in the API Reference but hopefully will in the future.
Bug Fixes
#1953: Fixed error when overwriting a parametrized fixture, while also reusing the super fixture value.
``` {.sourceCode .python}
conftest.py
import pytest
@pytest.fixture(params=[1, 2]) def foo(request): return request.param
test_foo.py
import pytest
@pytest.fixture def foo(foo): return foo * 2 ```
#4984: Fixed an internal error crash with
IndexError: list index out of rangewhen collecting a module which starts with a decorated function, the decorator raises, and assertion rewriting is enabled.#7591: pylint shouldn't complain anymore about unimplemented abstract methods when inheriting from File <non-python tests>.
#7628: Fixed test collection when a full path without a drive letter was passed to pytest on Windows (for example
\projects\tests\test.pyinstead ofc:\projects\tests\pytest.py).#7638: Fix handling of command-line options that appear as paths but trigger an OS-level syntax error on Windows, such as the options used internally by
pytest-xdist.#7742: Fixed INTERNALERROR when accessing locals / globals with faulty
exec.
Improved Documentation
- #1477: Removed faq.rst and its reference in contents.rst.
Trivial/Internal Changes
- #7536: The internal
junitxmlplugin has rewritten to usexml.etree.ElementTree. The order of attributes in XML elements might differ. Some unneeded escaping is no longer performed. - #7587: The dependency on the
more-itertoolspackage has been removed. - #7631: The result type of capfd.readouterr() <_pytest.capture.CaptureFixture.readouterr> (and similar) is no longer a namedtuple, but should behave like one in all respects. This was done for technical reasons.
- #7671: When collecting tests, pytest finds test classes and functions by examining the
attributes of python objects (modules, classes and instances). To speed up this
process, pytest now ignores builtin attributes (like
__class__,__delattr__and__new__) without consulting the python_classes and python_functions configuration options and without passing them to plugins using the pytest_pycollect_makeitem <_pytest.hookspec.pytest_pycollect_makeitem> hook.
- Python
Published by nicoddemus over 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.0.2
pytest 6.0.2 (2020-09-04)
Bug Fixes
- #7148: Fixed
--log-clipotentially causing unrelatedprintoutput to be swallowed. - #7672: Fixed log-capturing level restored incorrectly if
caplog.set_levelis called more than once. - #7686: Fixed NotSetType.token being used as the parameter ID when the parametrization list is empty. Regressed in pytest 6.0.0.
- #7707: Fix internal error when handling some exceptions that contain multiple lines or the style uses multiple lines (
--tb=linefor example).
- Python
Published by nicoddemus over 5 years ago
pytest - 6.0.0rc1
pytest 6.0.0rc1 (2020-07-08)
Breaking Changes
- #1316:
TestReport.longrepris now always an instance ofReprExceptionInfo. Previously it was astrwhen a test failed withpytest.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 warningor1 error) caused an unintended regression by changing the keys returned byparseoutcomes().Now the API guarantees to always return the plural form, so calls like this:
{.sourceCode .python} result = testdir.runpytest() result.assert_outcomes(error=1)Need to be changed to:
{.sourceCode .python} 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:
-kno longer matches against the names of the directories outside the test session root.Also,
pytest.Package.nameis now just the name of the directory containing the package's__init__.pyfile, instead of the full path. This is consistent with how the other nodes are named, and also one of the reasons why-kwould match against any directory containing the test suite.#7122: Expressions given to the
-mand-koptions are no longer evaluated using Python's eval. The format supportsor,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
TerminalWriterclass instead of using the one from thepylibrary. Plugins generally access this class throughTerminalReporter.writer,TerminalReporter.write()(and similar methods), or_pytest.config.create_terminal_writer().The following breaking changes were made:
- Output (
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), usewrite(flush=True)orterminal_writer.flush(). - Explicit Windows console support was removed, delegated to the colorama library.
- Support for writing
byteswas removed. - The
relinemethod andchars_on_current_lineproperty were removed. - The
stringioandencodingarguments was removed. - Support for passing a callable instead of a file was removed.
- Output (
#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-logsoption is removed. Use--show-captureinstead.#7226: Removed the unused
argsparameter frompytest.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:- The
deindentargument toSource()has been removed, now it is always true. - Support for zero or multiple arguments to
Source()has been removed. - Support for comparing
Sourcewith anstrhas been removed. - The methods
Source.isparseable()andSource.putaround()have been removed. - The method
Source.compile()and function_pytest._code.compile()have been removed; use plaincompile()instead. - The function
_pytest._code.source.getsource()has been removed; useSource()directly instead.
- The
Deprecations
#7210: The special
-k '-expr'syntax to-kis deprecated. Use-k 'not expr'instead.The special
-k 'expr:'syntax to-kis deprecated. Please open an issue if you use this and want a replacement.#4049:
pytest_warning_capturedis deprecated in favor of thepytest_warning_recordedhook.
Features
#1556: pytest now supports
pyproject.tomlfiles 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:``` {.sourceCode .toml}
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:
- `--no-header`: disables the initial header, including platform, version, and plugins.
- `--no-summary`: disables the final test summary, including warnings.
#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=importliboption that uses importlib to import test modules.Traditionally pytest used
__import__while changingsys.pathto import test modules (which also changessys.modulesas 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 insys.modules).--import-mode=importlibuses more fine grained import mechanisms fromimportlibwhich don't require pytest to changesys.pathorsys.modulesat all, eliminating much of the drawbacks of the previous mode.We intend to make
--import-mode=importlibthe 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_pluginsconfiguration 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.
Improvements
- #4375: The
pytestcommand now suppresses theBrokenPipeErrorerror message that is printed to stderr when the output ofpytestis piped and and the pipe is closed by the piped-to program (common examples arelessandhead). - #4391: Improved precision of test durations measurement.
CallInfoitems now have a new<CallInfo>.durationattribute, created usingtime.perf_counter(). This attribute is used to fill the<TestReport>.durationattribute, which is more accurate than the previous<CallInfo>.stop - <CallInfo>.start(as these are based ontime.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
--durationoption, 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
fdcapturing is used, through--capture=fdor thecapfdandcapfdbinaryfixtures, 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
--basetempargument 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:
--junitxmlnow includes the exception cause in themessageXML attribute for failures during setup and teardown.Previously:
{.sourceCode .xml} <error message="test setup failure">Now:
{.sourceCode .xml} <error message="failed on setup with "ValueError: Some error during setup"">
Bug Fixes
- #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.parametrizeto 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
--reportlogoption.#6924: Ensure a
unittest.IsolatedAsyncioTestCaseis 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.writerattribute.#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.skipin the SKIPPED report is now relative to invocation directory. Previously it was relative to root directory.#7110: Fixed regression:
asyncbase.TestCasetests are executed correctly again.#7126:
--setup-shownow doesn't raise an error when a bytes value is used as aparametrizeparameter when Python is called with the-bbflag.#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
ConfTestImportFailureis raised.#7180: Fix
_is_setup_pyfor files encoded differently than locale.#7215: Fix regression where running with
--pdbwould call unittest.TestCase.tearDown for skipped tests.#7253: When using
pytest.fixtureon a function directly, as inpytest.fixture(func), if theautouseorparamsarguments 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.skipifandpytest.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.
Improved Documentation
- #7202: The development guide now links to the contributing section of the docs and RELEASING.rst on GitHub.
- #7233: Add a note about
--strictand--strict-markersand the preference for the latter one. - #7345: Explain indirect parametrization and markers for fixtures.
Trivial/Internal Changes
- #7035: The
originalnameattribute of_pytest.python.Functionnow defaults tonameif not provided explicitly, and is always set. - #7264: The dependency on the
wcwidthpackage has been removed. - #7291: Replaced
py.iniconfigwith iniconfig. - #7295:
src/_pytest/config/__init__.pynow uses thewarningsmodule to report warnings instead ofsys.stderr.write. - #7356: Remove last internal uses of deprecated slave term from old
pytest-xdist. - #7357:
py>=1.8.2 is now required.
- Python
Published by nicoddemus over 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.0.1
pytest 6.0.1 (2020-07-30)
Bug Fixes
- #7394: Passing an empty
helpvalue toParser.add_optionis now accepted instead of crashing when runningpytest --help. PassingNoneraises a more informativeTypeError. - #7558: Fix pylint
not-callablelint onpytest.mark.parametrize()and the other builtin marks:skip,skipif,xfail,usefixtures,filterwarnings. - #7559: Fix regression in plugins using
TestReport.longreprtext(such aspytest-html) whenTestReport.longrepris not a string. - #7569: Fix logging capture handler's level not reset on teardown after a call to
caplog.set_level().
- Python
Published by nicoddemus over 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/6.0.0
pytest 6.0.0 (2020-07-28)
(Please see the full set of changes for this release also in the 6.0.0rc1 notes below)
Breaking Changes
#5584: PytestDeprecationWarning are now errors by default.
Following our plan to remove deprecated features with as little disruption as possible, all warnings of type
PytestDeprecationWarningnow 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.Xseries, it is possible to change the errors back into warnings as a stopgap measure by adding this to yourpytest.inifile:{.sourceCode .ini} [pytest] filterwarnings = ignore::pytest.PytestDeprecationWarningBut this will stop working when pytest
6.1is released.If you have concerns about the removal of a specific feature, please add a comment to #5584.
#7472: The
exec_()andis_true()methods of_pytest._code.Framehave been removed.
Features
- #7464: Added support for NO_COLOR and FORCE_COLOR environment variables to control colored output.
Improvements
- #7467:
--log-fileCLI option andlog_fileini marker now create subdirectories if needed. - #7489: The pytest.raises function has a clearer error message when
matchequals the obtained string but is not a regex match. In this case it is suggested to escape the regex.
Bug Fixes
- #7392: Fix the reported location of tests skipped with
@pytest.mark.skipwhen--runxfailis used. - #7491: tmpdir and tmp_path no longer raise an error if the lock to check for stale temporary directories is not accessible.
- #7517: Preserve line endings when captured via
capfd. - #7534: Restored the previous formatting of
TracebackEntry.__str__which was changed by accident.
Improved Documentation
- #7422: Clarified when the
usefixturesmark can apply fixtures to test. - #7441: Add a note about
-qoption used in getting started guide.
Trivial/Internal Changes
- #7389: Fixture scope
packageis no longer considered experimental.
pytest 6.0.0rc1 (2020-07-08)
Breaking Changes
- #1316:
TestReport.longrepris now always an instance ofReprExceptionInfo. Previously it was astrwhen a test failed withpytest.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 warningor1 error) caused an unintended regression by changing the keys returned byparseoutcomes().Now the API guarantees to always return the plural form, so calls like this:
{.sourceCode .python} result = testdir.runpytest() result.assert_outcomes(error=1)Need to be changed to:
{.sourceCode .python} 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:
-kno longer matches against the names of the directories outside the test session root.Also,
pytest.Package.nameis now just the name of the directory containing the package's__init__.pyfile, instead of the full path. This is consistent with how the other nodes are named, and also one of the reasons why-kwould match against any directory containing the test suite.#7122: Expressions given to the
-mand-koptions are no longer evaluated using Python's eval. The format supportsor,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
TerminalWriterclass instead of using the one from thepylibrary. Plugins generally access this class throughTerminalReporter.writer,TerminalReporter.write()(and similar methods), or_pytest.config.create_terminal_writer().The following breaking changes were made:
- Output (
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), usewrite(flush=True)orterminal_writer.flush(). - Explicit Windows console support was removed, delegated to the colorama library.
- Support for writing
byteswas removed. - The
relinemethod andchars_on_current_lineproperty were removed. - The
stringioandencodingarguments was removed. - Support for passing a callable instead of a file was removed.
- Output (
#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-logsoption is removed. Use--show-captureinstead.#7226: Removed the unused
argsparameter frompytest.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:- The
deindentargument toSource()has been removed, now it is always true. - Support for zero or multiple arguments to
Source()has been removed. - Support for comparing
Sourcewith anstrhas been removed. - The methods
Source.isparseable()andSource.putaround()have been removed. - The method
Source.compile()and function_pytest._code.compile()have been removed; use plaincompile()instead. - The function
_pytest._code.source.getsource()has been removed; useSource()directly instead.
- The
Deprecations
#7210: The special
-k '-expr'syntax to-kis deprecated. Use-k 'not expr'instead.The special
-k 'expr:'syntax to-kis deprecated. Please open an issue if you use this and want a replacement.#4049:
pytest_warning_capturedis deprecated in favor of thepytest_warning_recordedhook.
Features
#1556: pytest now supports
pyproject.tomlfiles 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:``` {.sourceCode .toml}
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:
- `--no-header`: disables the initial header, including platform, version, and plugins.
- `--no-summary`: disables the final test summary, including warnings.
#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=importliboption that uses importlib to import test modules.Traditionally pytest used
__import__while changingsys.pathto import test modules (which also changessys.modulesas 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 insys.modules).--import-mode=importlibuses more fine grained import mechanisms fromimportlibwhich don't require pytest to changesys.pathorsys.modulesat all, eliminating much of the drawbacks of the previous mode.We intend to make
--import-mode=importlibthe 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_pluginsconfiguration 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.
Improvements
- #4375: The
pytestcommand now suppresses theBrokenPipeErrorerror message that is printed to stderr when the output ofpytestis piped and and the pipe is closed by the piped-to program (common examples arelessandhead). - #4391: Improved precision of test durations measurement.
CallInfoitems now have a new<CallInfo>.durationattribute, created usingtime.perf_counter(). This attribute is used to fill the<TestReport>.durationattribute, which is more accurate than the previous<CallInfo>.stop - <CallInfo>.start(as these are based ontime.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
--durationoption, 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
fdcapturing is used, through--capture=fdor thecapfdandcapfdbinaryfixtures, 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
--basetempargument 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:
--junitxmlnow includes the exception cause in themessageXML attribute for failures during setup and teardown.Previously:
{.sourceCode .xml} <error message="test setup failure">Now:
{.sourceCode .xml} <error message="failed on setup with "ValueError: Some error during setup"">
Bug Fixes
- #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.parametrizeto 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
--reportlogoption.#6924: Ensure a
unittest.IsolatedAsyncioTestCaseis 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.writerattribute.#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.skipin the SKIPPED report is now relative to invocation directory. Previously it was relative to root directory.#7110: Fixed regression:
asyncbase.TestCasetests are executed correctly again.#7126:
--setup-shownow doesn't raise an error when a bytes value is used as aparametrizeparameter when Python is called with the-bbflag.#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
ConfTestImportFailureis raised.#7180: Fix
_is_setup_pyfor files encoded differently than locale.#7215: Fix regression where running with
--pdbwould call unittest.TestCase.tearDown for skipped tests.#7253: When using
pytest.fixtureon a function directly, as inpytest.fixture(func), if theautouseorparamsarguments 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.skipifandpytest.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.
Improved Documentation
- #7202: The development guide now links to the contributing section of the docs and RELEASING.rst on GitHub.
- #7233: Add a note about
--strictand--strict-markersand the preference for the latter one. - #7345: Explain indirect parametrization and markers for fixtures.
Trivial/Internal Changes
- #7035: The
originalnameattribute of_pytest.python.Functionnow defaults tonameif not provided explicitly, and is always set. - #7264: The dependency on the
wcwidthpackage has been removed. - #7291: Replaced
py.iniconfigwith iniconfig. - #7295:
src/_pytest/config/__init__.pynow uses thewarningsmodule to report warnings instead ofsys.stderr.write. - #7356: Remove last internal uses of deprecated slave term from old
pytest-xdist. - #7357:
py>=1.8.2 is now required.
- Python
Published by nicoddemus over 5 years ago
pytest - pytest 4.6.11 (2020-06-04)
Bug Fixes
- #6334: Fix summary entries appearing twice when
f/Fands/Sreport chars were used at the same time in the-rcommand-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 assignmentin_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.
- Python
Published by nicoddemus over 5 years ago
pytest - pytest 4.6.10 (2020-05-08)
6870: New
Config.invocation_argsattribute containing the unchanged arguments passed topytest.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.
- Python
Published by nicoddemus over 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.4.3
pytest 5.4.3 (2020-06-02)
Bug Fixes
- #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.
- #6956: Prevent pytest from printing ConftestImportFailure traceback to stdout.
- #7150: Prevent hiding the underlying exception when
ConfTestImportFailureis raised. - #7215: Fix regression where running with
--pdbwould call thetearDownmethods ofunittest.TestCasesubclasses for skipped tests.
- Python
Published by nicoddemus over 5 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.4.2
pytest 5.4.2 (2020-05-08)
Bug Fixes
- #6871: Fix crash with captured output when using the capsysbinary fixture <capsysbinary>.
- #6924: Ensure a
unittest.IsolatedAsyncioTestCaseis actually awaited. - #6925: Fix TerminalRepr instances to be hashable again.
- #6947: Fix regression where functions registered with
TestCase.addCleanupwere not being called on test failures. - #6951: Allow users to still set the deprecated
TerminalReporter.writerattribute. - #6992: Revert "tmpdir: clean up indirection via config for factories" #6767 as it breaks pytest-xdist.
- #7110: Fixed regression:
asyncbase.TestCasetests are executed correctly again. - #7143: Fix
File.from_constructorso it forwards extra keyword arguments to the constructor. - #7145: Classes with broken
__getattribute__methods are displayed correctly during failures. - #7180: Fix
_is_setup_pyfor files encoded differently than locale.
- Python
Published by nicoddemus almost 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.4.1
pytest 5.4.1 (2020-03-13)
Bug Fixes
#6909: Revert the change introduced by #6330, which required all arguments to
@pytest.mark.parametrizeto 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
--reportlogoption.
- Python
Published by nicoddemus almost 6 years ago
pytest - pytest 5.4.0 (2020-03-12)
Breaking Changes
#6316: Matching of
-k EXPRESSIONto test names is now case-insensitive.#6443: Plugins specified with
-pare now loaded after internal plugins, which results in their hooks being called before the internal ones.This makes the
-pbehavior consistent withPYTEST_PLUGINS.#6637: Removed the long-deprecated
pytest_itemstarthook.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_resultattribute ofFixtureDefis now set toNonewhen the result is unavailable, instead of being deleted.If your plugin performs checks like
hasattr(fixturedef, 'cached_result'), for example in apytest_fixture_post_finalizerhook implementation, replace it withfixturedef.cached_result is not None. If youdelthe attribute, set it toNoneinstead.
Deprecations
#3238: Option
--no-print-logsis deprecated and meant to be removed in a future release. If you use--no-print-logs, please try out--show-captureand provide feedback.--show-capturecommand-line option was added inpytest 3.5.0and allows to specify how to display captured output when tests fail:no,stdout,stderr,logorall(the default).#571: Deprecate the unused/broken [pytest_collect_directory]{.title-ref} hook. It was misaligned since the removal of the
Directorycollector 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
Noderelationships 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.writerattribute 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 withpy.io.TerminalWriter.
Features
- #4597: New
--capture=tee-sys <capture-method>{.interpreted-text role="ref"} option to allow both live printing and capturing of test output. - #5712: Now all arguments to
@pytest.mark.parametrizeneed to be explicitly declared in the function signature or viaindirect. 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. - #6454: Changed default for [-r]{.title-ref} to [fE]{.title-ref}, which displays failures and errors in the
short test summary <pytest.detailed_failed_tests_usage>{.interpreted-text role="ref"}. [-rN]{.title-ref} can be used to disable it (the old behavior). - #6469: New options have been added to the
junit_logging{.interpreted-text role="confval"} option:log,out-err, andall. - #6834: Excess warning summaries are now collapsed per file to ensure readable display of warning summaries.
Improvements
#1857:
pytest.mark.parametrizeaccepts integers foridsagain, 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.mktempnow fails when given absolute and non-normalized paths.#5984: The
pytest_warning_capturedhook now receives alocationparameter with the code location that generated the warning.#6213: pytester: the
testdirfixture respects environment settings from themonkeypatchfixture for inner runs.#6247:
--fulltraceis 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
pygmentsis installed.Users are encouraged to install
pygmentsinto their environment and provide feedback, because the plan is to makepygmentsa regular dependency in the future.#6795: Import usage error message with invalid [-o]{.title-ref} option.
#759:
pytest.mark.parametrizesupports iterators and generators forids.
Bug Fixes
#310: Add support for calling [pytest.xfail()]{.title-ref} and [pytest.importorskip()]{.title-ref} with doctests.
#3823:
--tracenow 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-failedto collect new tests from files with known failures.#5928: Report
PytestUnknownMarkWarningat the level of the user\'s code, notpytest\'s.#5991: Fix interaction with
--pdband unittests: do not use unittest\'sTestCase.debug().#6334: Fix summary entries appearing twice when
f/Fands/Sreport chars were used at the same time in the-rcommand-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 ofa == bcannot generally be converted to [bool]{.title-ref}. The implemented fix replaces [==]{.title-ref} withis.#6557: Make capture output streams
.write()method return the same return value from original streams.#6566: Fix
EncodedFile.writelinesto call the underlying buffer\'swritelinesmethod.#6575: Fix internal crash when
faulthandlerstarts initialized (for example withPYTHONFAULTHANDLER=1environment variable set) andfaulthandler_timeoutdefined 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 thepytest_sessionfinish <_pytest.hookspec.pytest_sessionfinish>{.interpreted-text role="func"} hook. This includes quitting from a debugger.#6752: When :py
pytest.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.
Improved Documentation
- #6696: Add list of fixtures to start of fixture chapter.
- #6742: Expand first sentence on fixtures into a paragraph.
Trivial/Internal Changes
- #6404: Remove usage of
parsermodule, deprecated in Python 3.9.
- Python
Published by RonnyPfannschmidt almost 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.3.5
pytest 5.3.5 (2020-01-29)
Bug Fixes
- #6517: Fix regression in pytest 5.3.4 causing an INTERNALERROR due to a wrong assertion.
- Python
Published by nicoddemus about 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.3.4
pytest 5.3.4 (2020-01-20)
Bug Fixes
- #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 a new release while we continue to look for a solution.
- Python
Published by nicoddemus about 6 years ago
pytest - 5.3.3
pytest 5.3.3 (2020-01-16)
Bug Fixes
- #2780: Captured
output during teardown is shown with
-rP. - #5971: Fix a
pytest-xdistcrash when dealing with exceptions raised in subprocesses created by themultiprocessingmodule. - #6436: FixtureDef <_pytest.fixtures.FixtureDef> objects now properly register their finalizers with autouse and parameterized fixtures that execute before them in the fixture stack so they are torn down at the right times, and in the right order.
- #6532: Fix
parsing of outcomes containing multiple errors with
testdirresults (regression in 5.3.0).
Trivial/Internal Changes
- #6350: Optimized automatic renaming of test parameter IDs.
- Python
Published by nicoddemus about 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/4.6.9
pytest 4.6.9 (2020-01-04)
Bug Fixes
- #6301: Fix
assertion rewriting for egg-based distributions and
editableinstalls (pip install --editable).
- Python
Published by nicoddemus about 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/4.6.8
pytest 4.6.8 (2019-12-19)
Features
- #5471: JUnit XML now includes a timestamp and hostname in the testsuite tag.
Bug Fixes
- #5430: junitxml: Logs for failed test are now passed to junit report in case the test fails during call phase.
Trivial/Internal Changes
- #6345: Pin
coloramato0.4.1only for Python 3.4 so newer Python versions can still receive colorama updates.
- Python
Published by nicoddemus about 6 years ago
pytest -
pytest 5.3.2 (2019-12-13)
Improvements
#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.
Bug Fixes
- #5430: junitxml: Logs for failed test are now passed to junit report in case the test fails during call phase.
- #6290: The
supporting files in the
.pytest_cachedirectory are kept with--cache-clear, which only clears cached values now. - #6301: Fix
assertion rewriting for egg-based distributions and
editableinstalls (pip install --editable).
- Python
Published by nicoddemus about 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/4.6.7
pytest 4.6.7 (2019-12-05)
Bug Fixes
- #5477: The XML
file produced by
--junitxmlnow correctly contain a<testsuites>root element. - #6044: Properly
ignore
FileNotFoundError(OSError.errno == NOENTin Python 2) exceptions when trying to remove old temporary directories, for instance when multiple processes try to remove the same directory (common withpytest-xdistfor example).
- Python
Published by nicoddemus about 6 years ago
pytest -
pytest 5.3.1 (2019-11-25)
Improvements
- #6231: Improve check for misspelling of
pytest.mark.parametrize. - #6257: Handle exit.Exception raised in notify_exception (via pytest_internalerror), e.g. when quitting pdb from post mortem.
Bug Fixes
- #5914: pytester: fix
no_fnmatch_linewhen used after positive matching. - #6082: Fix line detection for doctest samples inside
propertydocstrings, as a workaround to bpo-17446. - #6254: Fix compatibility with pytest-parallel (regression in pytest 5.3.0).
- #6255: Clear the
sys.last_traceback,sys.last_typeandsys.last_valueattributes by deleting them instead of setting them toNone. This better matches the behaviour of the Python standard library.
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.3.0
pytest 5.3.0 (2019-11-19)
Deprecations
#6179: The default value of
junit_familyoption will change toxunit2in 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
--junitxmloption is given in the command line butjunit_familyis not explicitly configured inpytest.ini.For more information, see the docs.
Features
#4488: The pytest team has created the pytest-reportlog plugin, which provides a new
--report-log=FILEoption 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
--resultlogoption, which is deprecated and meant to be removed in a future release. If you use--resultlog, please try outpytest-reportlogand 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
.pycfiles even on file systems without permissions.#5515: Allow selective auto-indentation of multiline log messages.
Adds command line option
--log-auto-indent, config optionlog_auto_indentand support for per-entry configuration of indentation behavior on calls tologging.log().Alters the default for auto-indention from
ontooff. 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:
pytesterlearned 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:{.sourceCode .python} assert re.match(pat, result.stdout.str()) is NoneOr the
inoperator:{.sourceCode .python} 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. Forapproxcomparisons to returnTrue, the actual value should fall within this circle.#6061: Added the pluginmanager as an argument to
pytest_addoptionso 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.
Improvements
- #5061: Use multiple colors with terminal summary statistics.
- #5630: Quitting
from debuggers is now properly handled in
doctestitems. #5924: Improved verbose diff output with sequences.
Before:
{.sourceCode .} 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:
{.sourceCode .} 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.argsis now always atupleto better convey that it should be immutable and avoid accidental modifications.#6023:
pytest.mainnow returns apytest.ExitCodeinstance now, except for when custom exit codes are used (where it returnsintthen 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.spawndoes 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
--coas a synonym to--collect-only.#6148:
atomicwritesis 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.setrobustness and performance.
Bug Fixes
- #2049: Fixed
--setup-planshowing inaccurate information about fixture lifetimes. - #2548: Fixed line offset mismatch of skipped tests in terminal summary.
#6039: The
PytestDoctestRunneris now properly invalidated when unconfiguring the doctest plugin.This is important when used with
pytester'srunpytest_inprocess.#6047: BaseExceptions are now handled in
saferepr, which includespytest.fail.Exceptionetc.#6074: pytester: fixed order of arguments in
rm_rfwarning when cleaning up temporary directories, and do not emit warnings for errors withos.open.#6189: Fixed result of
getmodpathmethod.
Trivial/Internal Changes
- #4901:
RunResultfrompytesternow displays the mnemonic of theretattribute when it is a validpytest.ExitCodevalue.
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.2.4
pytest 5.2.4 (2019-11-15)
Bug Fixes
- #6194: Fix
incorrect discovery of non-test
__init__.pyfiles. - #6197: Revert
"The first test in a package (
__init__.py) marked with@pytest.mark.skipis now correctly skipped.".
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.2.3
pytest 5.2.3 (2019-11-14)
Bug Fixes
- #5830: The
first test in a package (
__init__.py) marked with@pytest.mark.skipis now correctly skipped. - #6099: Fix
--tracewhen used with parametrized functions. - #6183: Using
requestas a parameter name in@pytest.mark.parametrizenow produces a more user-friendly error.
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.2.2
pytest 5.2.2 (2019-10-24)
Bug Fixes
- #5206: Fix
--nfto not forget about known nodeids with partial test selection. - #5906: Fix
crash with
KeyboardInterruptduring--setup-show. - #5946: Fixed issue when parametrizing fixtures with numpy arrays (and possibly other sequence-like types).
- #6044: Properly
ignore
FileNotFoundErrorexceptions when trying to remove old temporary directories, for instance when multiple processes try to remove the same directory (common withpytest-xdistfor example).
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/4.6.6
pytest 4.6.6 (2019-10-11)
Bug Fixes
- #5523: Fixed
using multiple short options together in the command-line (for
example
-vs) in Python 3.8+. - #5537: Replace
importlib_metadatabackport withimportlib.metadatafrom the standard library on Python 3.8+. - #5806: Fix
"lexer" being used when uploading to bpaste.net from
--pastebinto "text". - #5902: Fix
warnings about deprecated
cmpattribute inattrs>=19.2.
Trivial/Internal Changes
- #5801: Fixes
python version checks (detected by
flake8-2020) in case python4 becomes a thing.
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.2.1
pytest 5.2.1 (2019-10-06)
Bug Fixes
- #5902: Fix
warnings about deprecated
cmpattribute inattrs>=19.2.
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.2.0
pytest 5.2.0 (2019-09-28)
Deprecations
- #1682: Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them as a keyword argument instead.
Features
- #1682: The
scopeparameter of@pytest.fixturecan now be a callable that receives the fixture name and theconfigobject as keyword-only parameters. See the docs for more information. - #5764: New
behavior of the
--pastebinoption: failures to connect to the pastebin server are reported, without failing the pytest run
Bug Fixes
- #5806: Fix
"lexer" being used when uploading to bpaste.net from
--pastebinto "text". - #5884: Fix
--setup-onlyand--setup-showfor custom pytest items.
Trivial/Internal Changes
- #5056: The
HelpFormatter uses
py.io.get_terminal_widthfor better width detection.
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.1.3
pytest 5.1.3 (2019-09-18)
Bug Fixes
- #5807: Fix pypy3.6 (nightly) on windows.
- #5811: Handle
--fulltracecorrectly withpytest.raises. - #5819: Windows: Fix regression with conftest whose qualified name contains uppercase characters (introduced by #5792).
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.1.2
pytest 5.1.2 (2019-08-30)
Bug Fixes
- #2270: Fixed
selfreference in function-scoped fixtures defined plugin classes: previouslyselfwould be a reference to a test class, not the plugin class. - #570: Fixed long standing issue where fixture scope was not respected when indirect fixtures were used during parametrization.
- #5782: Fix
decoding error when printing an error response from
--pastebin. - #5786: Chained
exceptions in test and collection reports are now correctly
serialized, allowing plugins like
pytest-xdistto display them properly. - #5792: Windows:
Fix error that occurs in certain circumstances when loading
conftest.pyfrom a working directory that has casing other than the one stored in the filesystem (e.g.,c:\testinstead ofC:\test).
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.1.1
pytest 5.1.1 (2019-08-20)
Bug Fixes
- #5751: Fixed
TypeErrorwhen importing pytest on Python 3.5.0 and 3.5.1.
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.1.0
pytest 5.1.0 (2019-08-15)
Removals
#5180: As per our policy, the following features have been deprecated in the 4.X series and are now removed:
-
Request.getfuncargvalue: useRequest.getfixturevalueinstead. -
pytest.raisesandpytest.warnsno longer support strings as the second argument. -
messageparameter ofpytest.raises. -
pytest.raises,pytest.warnsandParameterSet.paramnow use native keyword-only syntax. This might change the exception message from previous versions, but they still raiseTypeErroron unknown keyword arguments as before. -
pytest.configglobal variable. -
tmpdir_factory.ensuretempmethod. -
pytest_logwarninghook. -
RemovedInPytest4Warningwarning type. -
requestis now a reserved name for fixtures.
For more information consult Deprecations and Removals in the docs.
-
#5565: Removed unused support code for unittest2.
The
unittest2backport 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
unittest2is 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.xfailandpytest.skipno longer support bytes for the message argument.This was supported for Python 2 where it was tempting to use
"message"instead ofu"message".Python 3 code is unlikely to pass
bytesto these functions. If you do, please decode it to anstrbeforehand.
Features
- #5564: New
Config.invocation_argsattribute containing the unchanged arguments passed topytest.main(). - #5576: New NUMBER option for doctests to ignore irrelevant differences in floating-point numbers. Inspired by Sébastien Boisgérault\'s numtest extension for doctest.
Improvements
#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) =====
Bug Fixes
- #4344: Fix RuntimeError/StopIteration when trying to collect package with \"__init__.py\" only.
- #5115: Warnings
issued during
pytest_configureare explicitly not treated as errors, even if configured as such, because it otherwise completely breaks pytest. - #5477: The XML
file produced by
--junitxmlnow correctly contain a<testsuites>root element. - #5523: Fixed
using multiple short options together in the command-line (for
example
-vs) in Python 3.8+. - #5524: Fix
issue where
tmp_pathandtmpdirwould not remove directories containing files marked as read-only, which could lead to pytest crashing when executed a second time with the--basetempoption. - #5537: Replace
importlib_metadatabackport withimportlib.metadatafrom the standard library on Python 3.8+. - #5578: Improve
type checking for some exception-raising functions (
pytest.xfail,pytest.skip, etc) so they provide better error messages when users meant to use marks (for example@pytest.xfailinstead of@pytest.mark.xfail). - #5606: Fixed
internal error when test functions were patched with objects that
cannot be compared for truth values against others, like
numpyarrays. - #5634:
pytest.exitis now correctly handled inunittestcases. This makesunittestcases handlequitfrom pytest\'s pdb correctly. - #5650: Improved output when parsing an ini configuration file fails.
- #5701: Fix
collection of
staticmethodobjects defined withfunctools.partial. - #5734: Skip
async generator test functions, and update the warning message to
refer to
async deffunctions.
Improved Documentation
- #5669: Add
docstring for
Testdir.copy_example.
Trivial/Internal Changes
- #5095: XML
files of the
xunit2family are now validated against the schema by pytest\'s own test suite to avoid future regressions. - #5516: Cache node splitting function which can improve collection performance in very large test suites.
- #5603:
Simplified internal
SafeReprclass and removed some dead code. - #5664: When
invoking pytest\'s own testsuite with
PYTHONDONTWRITEBYTECODE=1, thetest_xfail_handlingtest no longer fails. - #5684: Replace
manual handling of
OSError.errnoin the codebase by newOSErrorsubclasses (PermissionError,FileNotFoundError, etc.).
- Python
Published by nicoddemus over 6 years ago
pytest - https://github.com/pytest-dev/pytest/releases/tag/5.0.1
pytest 5.0.1 (2019-07-04)
Bug Fixes
- #5479: Improve
quoting in
raisesmatch failure message. - #5523: Fixed
using multiple short options together in the command-line (for
example
-vs) in Python 3.8+. - #5547:
--step-wisenow handlesxfail(strict=True)markers properly.
Improved Documentation
- #5517: Improve \"Declaring new hooks\" section in chapter \"Writing Plugins\"
- Python
Published by nicoddemus over 6 years ago
pytest -
Bug Fixes
#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_pathandtmpdirwould not remove directories containing files marked as read-only, which could lead to pytest crashing when executed a second time with the--basetempoption.#5547:
--step-wisenow handlesxfail(strict=True)markers properly.#5650: Improved output when parsing an ini configuration file fails.
- Python
Published by nicoddemus over 6 years ago