Skip to content

Commit 3766060

Browse files
authored
Merge branch 'master' into trial-envs
2 parents 2574da8 + e0c48b4 commit 3766060

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,4 @@ Tyler Goodlet
141141
Vasily Kuznetsov
142142
Wouter van Ackooy
143143
Xuecong Liao
144+
Eli Boyarski

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,26 @@
1717
* Fix ``pytester`` internal plugin to work correctly with latest versions of
1818
``zope.interface`` (`#1989`_). Thanks `@nicoddemus`_ for the PR.
1919

20+
* Assert statements of the ``pytester`` plugin again benefit from assertion rewriting (`#1920`_).
21+
Thanks `@RonnyPfannschmidt`_ for the report and `@nicoddemus`_ for the PR.
22+
2023
* Specifying tests with colons like ``test_foo.py::test_bar`` for tests in
2124
subdirectories with ini configuration files now uses the correct ini file
2225
(`#2148`_). Thanks `@pelme`_.
2326

27+
* Fail ``testdir.runpytest().assert_outcomes()`` explicitly if the pytest
28+
terminal output it relies on is missing. Thanks to `@eli-b`_ for the PR.
29+
2430
*
2531

2632
.. _@lesteve: https://github.com/lesteve
2733
.. _@malinoff: https://github.com/malinoff
2834
.. _@pelme: https://github.com/pelme
35+
.. _@eli-b: https://github.com/eli-b
36+
2937

3038
.. _#1989: https://github.com/pytest-dev/pytest/issues/1989
39+
.. _#1920: https://github.com/pytest-dev/pytest/issues/1920
3140
.. _#2129: https://github.com/pytest-dev/pytest/issues/2129
3241
.. _#2148: https://github.com/pytest-dev/pytest/issues/2148
3342
.. _#2150: https://github.com/pytest-dev/pytest/issues/2150

_pytest/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def import_plugin(self, modname):
421421
importspec = "_pytest." + modname
422422
else:
423423
importspec = modname
424-
self.rewrite_hook.mark_rewrite(modname)
424+
self.rewrite_hook.mark_rewrite(importspec)
425425
try:
426426
__import__(importspec)
427427
except ImportError as e:

_pytest/pytester.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def parseoutcomes(self):
367367
for num, cat in outcomes:
368368
d[cat] = int(num)
369369
return d
370+
raise ValueError("Pytest terminal report not found")
370371

371372
def assert_outcomes(self, passed=0, skipped=0, failed=0):
372373
""" assert that the specified outcomes appear with the respective

testing/test_assertion.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ def test(check_first):
5858
assert 0
5959
result.stdout.fnmatch_lines([expected])
6060

61+
def test_rewrite_assertions_pytester_plugin(self, testdir):
62+
"""
63+
Assertions in the pytester plugin must also benefit from assertion
64+
rewriting (#1920).
65+
"""
66+
testdir.makepyfile("""
67+
pytest_plugins = ['pytester']
68+
def test_dummy_failure(testdir): # how meta!
69+
testdir.makepyfile('def test(): assert 0')
70+
r = testdir.inline_run()
71+
r.assertoutcome(passed=1)
72+
""")
73+
result = testdir.runpytest_subprocess()
74+
result.stdout.fnmatch_lines([
75+
'*assert 1 == 0*',
76+
])
77+
6178
@pytest.mark.parametrize('mode', ['plain', 'rewrite'])
6279
def test_pytest_plugins_rewrite(self, testdir, mode):
6380
contents = {

testing/test_pytester.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,10 @@ def test_inline_run_clean_modules(testdir):
124124
test_mod.write("def test_foo(): assert False")
125125
result2 = testdir.inline_run(str(test_mod))
126126
assert result2.ret == EXIT_TESTSFAILED
127+
128+
def test_assert_outcomes_after_pytest_erro(testdir):
129+
testdir.makepyfile("def test_foo(): assert True")
130+
131+
result = testdir.runpytest('--unexpected-argument')
132+
with pytest.raises(ValueError, message="Pytest terminal report not found"):
133+
result.assert_outcomes(passed=0)

0 commit comments

Comments
 (0)