Compare commits
5 Commits
should_do_
...
5.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d0f3baa2b | ||
|
|
b9e2cd0a81 | ||
|
|
a84fcbf5b2 | ||
|
|
59c1bfada7 | ||
|
|
3267f64724 |
@@ -6,6 +6,7 @@ Release announcements
|
||||
:maxdepth: 2
|
||||
|
||||
|
||||
release-5.4.1
|
||||
release-5.4.0
|
||||
release-5.3.5
|
||||
release-5.3.4
|
||||
|
||||
18
doc/en/announce/release-5.4.1.rst
Normal file
18
doc/en/announce/release-5.4.1.rst
Normal file
@@ -0,0 +1,18 @@
|
||||
pytest-5.4.1
|
||||
=======================================
|
||||
|
||||
pytest 5.4.1 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Bruno Oliveira
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
@@ -28,6 +28,20 @@ with advance notice in the **Deprecations** section of releases.
|
||||
|
||||
.. towncrier release notes start
|
||||
|
||||
pytest 5.4.1 (2020-03-13)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#6909 <https://github.com/pytest-dev/pytest/issues/6909>`_: Revert the change introduced by `#6330 <https://github.com/pytest-dev/pytest/pull/6330>`_, which required all arguments to ``@pytest.mark.parametrize`` to be explicitly defined in the function signature.
|
||||
|
||||
The intention of the original change was to remove what was expected to be an unintended/surprising behavior, but it turns out many people relied on it, so the restriction has been reverted.
|
||||
|
||||
|
||||
- `#6910 <https://github.com/pytest-dev/pytest/issues/6910>`_: Fix crash when plugins return an unknown stats while using the ``--reportlog`` option.
|
||||
|
||||
|
||||
pytest 5.4.0 (2020-03-12)
|
||||
=========================
|
||||
|
||||
@@ -63,10 +77,10 @@ Breaking Changes
|
||||
Deprecations
|
||||
------------
|
||||
|
||||
- `#3238 <https://github.com/pytest-dev/pytest/issues/3238>`_: Option ``--no-print-logs`` is deprecated and meant to be removed in a future release. If you use ``--no-print-logs``, please try out ``--show-capture`` and
|
||||
provide feedback.
|
||||
|
||||
``--show-capture`` command-line option was added in ``pytest 3.5.0`` and allows to specify how to
|
||||
- `#3238 <https://github.com/pytest-dev/pytest/issues/3238>`_: Option ``--no-print-logs`` is deprecated and meant to be removed in a future release. If you use ``--no-print-logs``, please try out ``--show-capture`` and
|
||||
provide feedback.
|
||||
|
||||
``--show-capture`` command-line option was added in ``pytest 3.5.0`` and allows to specify how to
|
||||
display captured output when tests fail: ``no``, ``stdout``, ``stderr``, ``log`` or ``all`` (the default).
|
||||
|
||||
|
||||
|
||||
@@ -402,9 +402,6 @@ The result of this test will be successful:
|
||||
|
||||
.. regendoc:wipe
|
||||
|
||||
Note, that each argument in `parametrize` list should be explicitly declared in corresponding
|
||||
python test function or via `indirect`.
|
||||
|
||||
Parametrizing test methods through per-class configuration
|
||||
--------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import functools
|
||||
import inspect
|
||||
import itertools
|
||||
import sys
|
||||
import warnings
|
||||
from collections import defaultdict
|
||||
@@ -1277,8 +1278,10 @@ class FixtureManager:
|
||||
else:
|
||||
argnames = ()
|
||||
|
||||
usefixtures = get_use_fixtures_for_node(node)
|
||||
initialnames = usefixtures + argnames
|
||||
usefixtures = itertools.chain.from_iterable(
|
||||
mark.args for mark in node.iter_markers(name="usefixtures")
|
||||
)
|
||||
initialnames = tuple(usefixtures) + argnames
|
||||
fm = node.session._fixturemanager
|
||||
initialnames, names_closure, arg2fixturedefs = fm.getfixtureclosure(
|
||||
initialnames, node, ignore_args=self._get_direct_parametrize_args(node)
|
||||
@@ -1475,12 +1478,3 @@ class FixtureManager:
|
||||
for fixturedef in fixturedefs:
|
||||
if nodes.ischildnode(fixturedef.baseid, nodeid):
|
||||
yield fixturedef
|
||||
|
||||
|
||||
def get_use_fixtures_for_node(node) -> Tuple[str, ...]:
|
||||
"""Returns the names of all the usefixtures() marks on the given node"""
|
||||
return tuple(
|
||||
str(name)
|
||||
for mark in node.iter_markers(name="usefixtures")
|
||||
for name in mark.args
|
||||
)
|
||||
|
||||
@@ -936,8 +936,6 @@ class Metafunc:
|
||||
|
||||
arg_values_types = self._resolve_arg_value_types(argnames, indirect)
|
||||
|
||||
self._validate_explicit_parameters(argnames, indirect)
|
||||
|
||||
# Use any already (possibly) generated ids with parametrize Marks.
|
||||
if _param_mark and _param_mark._param_ids_from:
|
||||
generated_ids = _param_mark._param_ids_from._param_ids_generated
|
||||
@@ -1110,39 +1108,6 @@ class Metafunc:
|
||||
pytrace=False,
|
||||
)
|
||||
|
||||
def _validate_explicit_parameters(
|
||||
self,
|
||||
argnames: typing.Sequence[str],
|
||||
indirect: Union[bool, typing.Sequence[str]],
|
||||
) -> None:
|
||||
"""
|
||||
The argnames in *parametrize* should either be declared explicitly via
|
||||
indirect list or in the function signature
|
||||
|
||||
:param List[str] argnames: list of argument names passed to ``parametrize()``.
|
||||
:param indirect: same ``indirect`` parameter of ``parametrize()``.
|
||||
:raise ValueError: if validation fails
|
||||
"""
|
||||
if isinstance(indirect, bool):
|
||||
parametrized_argnames = [] if indirect else argnames
|
||||
else:
|
||||
parametrized_argnames = [arg for arg in argnames if arg not in indirect]
|
||||
|
||||
if not parametrized_argnames:
|
||||
return
|
||||
|
||||
funcargnames = _pytest.compat.getfuncargnames(self.function)
|
||||
usefixtures = fixtures.get_use_fixtures_for_node(self.definition)
|
||||
|
||||
for arg in parametrized_argnames:
|
||||
if arg not in funcargnames and arg not in usefixtures:
|
||||
func_name = self.function.__name__
|
||||
msg = (
|
||||
'In function "{func_name}":\n'
|
||||
'Parameter "{arg}" should be declared explicitly via indirect or in function itself'
|
||||
).format(func_name=func_name, arg=arg)
|
||||
fail(msg, pytrace=False)
|
||||
|
||||
|
||||
def _find_parametrized_scope(argnames, arg2fixturedefs, indirect):
|
||||
"""Find the most appropriate scope for a parametrized call based on its arguments.
|
||||
|
||||
@@ -77,10 +77,10 @@ class ResultLog:
|
||||
longrepr = ""
|
||||
elif report.passed:
|
||||
longrepr = ""
|
||||
elif report.failed:
|
||||
longrepr = str(report.longrepr)
|
||||
elif report.skipped:
|
||||
longrepr = str(report.longrepr[2])
|
||||
else:
|
||||
longrepr = str(report.longrepr)
|
||||
self.log_outcome(report, code, longrepr)
|
||||
|
||||
def pytest_collectreport(self, report):
|
||||
|
||||
@@ -463,7 +463,7 @@ class TestFunction:
|
||||
return '3'
|
||||
|
||||
@pytest.mark.parametrize('fix2', ['2'])
|
||||
def test_it(fix1, fix2):
|
||||
def test_it(fix1):
|
||||
assert fix1 == '21'
|
||||
assert not fix3_instantiated
|
||||
"""
|
||||
|
||||
@@ -36,9 +36,6 @@ class TestMetafunc:
|
||||
class DefinitionMock(python.FunctionDefinition):
|
||||
obj = attr.ib()
|
||||
|
||||
def listchain(self):
|
||||
return []
|
||||
|
||||
names = fixtures.getfuncargnames(func)
|
||||
fixtureinfo = FuncFixtureInfoMock(names) # type: Any
|
||||
definition = DefinitionMock._create(func) # type: Any
|
||||
@@ -1902,51 +1899,3 @@ class TestMarkersWithParametrization:
|
||||
"*= 6 passed in *",
|
||||
]
|
||||
)
|
||||
|
||||
def test_parametrize_explicit_parameters_func(self, testdir: Testdir) -> None:
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fixture(arg):
|
||||
return arg
|
||||
|
||||
@pytest.mark.parametrize("arg", ["baz"])
|
||||
def test_without_arg(fixture):
|
||||
assert "baz" == fixture
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(error=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
'*In function "test_without_arg"*',
|
||||
'*Parameter "arg" should be declared explicitly via indirect or in function itself*',
|
||||
]
|
||||
)
|
||||
|
||||
def test_parametrize_explicit_parameters_method(self, testdir: Testdir) -> None:
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
class Test:
|
||||
@pytest.fixture
|
||||
def test_fixture(self, argument):
|
||||
return argument
|
||||
|
||||
@pytest.mark.parametrize("argument", ["foobar"])
|
||||
def test_without_argument(self, test_fixture):
|
||||
assert "foobar" == test_fixture
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(error=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
'*In function "test_without_argument"*',
|
||||
'*Parameter "argument" should be declared explicitly via indirect or in function itself*',
|
||||
]
|
||||
)
|
||||
|
||||
@@ -193,6 +193,42 @@ def test_no_resultlog_on_slaves(testdir):
|
||||
assert resultlog_key not in config._store
|
||||
|
||||
|
||||
def test_unknown_teststatus(testdir):
|
||||
"""Ensure resultlog correctly handles unknown status from pytest_report_teststatus
|
||||
|
||||
Inspired on pytest-rerunfailures.
|
||||
"""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test():
|
||||
assert 0
|
||||
"""
|
||||
)
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def pytest_report_teststatus(report):
|
||||
if report.outcome == 'rerun':
|
||||
return "rerun", "r", "RERUN"
|
||||
|
||||
@pytest.hookimpl(hookwrapper=True)
|
||||
def pytest_runtest_makereport():
|
||||
res = yield
|
||||
report = res.get_result()
|
||||
if report.when == "call":
|
||||
report.outcome = 'rerun'
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--resultlog=result.log")
|
||||
result.stdout.fnmatch_lines(
|
||||
["test_unknown_teststatus.py r *[[]100%[]]", "* 1 rerun *"]
|
||||
)
|
||||
|
||||
lines = testdir.tmpdir.join("result.log").readlines(cr=0)
|
||||
assert lines[0] == "r test_unknown_teststatus.py::test"
|
||||
|
||||
|
||||
def test_failure_issue380(testdir):
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user