Skip to content

Commit

Permalink
ensure we also see warnings on generator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Nov 23, 2018
1 parent ada38c1 commit b8cd78c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,9 @@ def pytest_pycollect_makeitem(collector, name, obj):
elif getattr(obj, "__test__", True):
if is_generator(obj):
res = Function(name, parent=collector)
res.add_marker(
MARK_GEN.xfail(
run=False, reason=deprecated.YIELD_TESTS.format(name=name)
)
)
reason = deprecated.YIELD_TESTS.format(name=name)
res.add_marker(MARK_GEN.xfail(run=False, reason=reason))
res.warn(PytestWarning(reason))
else:
res = list(collector._genfunctions(name, obj))
outcome.force_result(res)
Expand Down
18 changes: 13 additions & 5 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from _pytest.terminal import getreportopt
from _pytest.terminal import repr_pythonversion
from _pytest.terminal import TerminalReporter
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG

DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"])

Expand Down Expand Up @@ -585,8 +584,9 @@ def test_showlocals():
]
)

def test_verbose_reporting(self, testdir, pytestconfig):
p1 = testdir.makepyfile(
@pytest.fixture
def verbose_testfile(self, testdir):
return testdir.makepyfile(
"""
import pytest
def test_fail():
Expand All @@ -602,7 +602,12 @@ def check(x):
yield check, 0
"""
)
result = testdir.runpytest(p1, "-v", SHOW_PYTEST_WARNINGS_ARG)

def test_verbose_reporting(self, verbose_testfile, testdir, pytestconfig):

result = testdir.runpytest(
verbose_testfile, "-v", "-Walways::pytest.PytestWarning"
)
result.stdout.fnmatch_lines(
[
"*test_verbose_reporting.py::test_fail *FAIL*",
Expand All @@ -613,10 +618,13 @@ def check(x):
)
assert result.ret == 1

def test_verbose_reporting_xdist(self, verbose_testfile, testdir, pytestconfig):
if not pytestconfig.pluginmanager.get_plugin("xdist"):
pytest.skip("xdist plugin not installed")

result = testdir.runpytest(p1, "-v", "-n 1", SHOW_PYTEST_WARNINGS_ARG)
result = testdir.runpytest(
verbose_testfile, "-v", "-n 1", "-Walways::pytest.PytestWarning"
)
result.stdout.fnmatch_lines(["*FAIL*test_verbose_reporting.py::test_fail*"])
assert result.ret == 1

Expand Down

0 comments on commit b8cd78c

Please sign in to comment.