Skip to content

Commit

Permalink
Merge pull request #2212 from nicoddemus/pytester-rewrite
Browse files Browse the repository at this point in the history
Assert statements of the pytester plugin again benefit from assertion rewriting

fixes #1920
  • Loading branch information
RonnyPfannschmidt authored Jan 20, 2017
2 parents 7b4368f + c477f09 commit e0c48b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
expected warnings and the list of caught warnings is added to the
error message. Thanks `@lesteve`_ for the PR.

* Assert statements of the ``pytester`` plugin again benefit from assertion rewriting (`#1920`_).
Thanks `@RonnyPfannschmidt`_ for the report and `@nicoddemus`_ for the PR.

* Specifying tests with colons like ``test_foo.py::test_bar`` for tests in
subdirectories with ini configuration files now uses the correct ini file
(`#2148`_). Thanks `@pelme`_.
Expand All @@ -28,6 +31,7 @@
.. _@pelme: https://github.com/pelme
.. _@eli-b: https://github.com/eli-b

.. _#1920: https://github.com/pytest-dev/pytest/issues/1920
.. _#2129: https://github.com/pytest-dev/pytest/issues/2129
.. _#2148: https://github.com/pytest-dev/pytest/issues/2148
.. _#2150: https://github.com/pytest-dev/pytest/issues/2150
Expand Down
2 changes: 1 addition & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def import_plugin(self, modname):
importspec = "_pytest." + modname
else:
importspec = modname
self.rewrite_hook.mark_rewrite(modname)
self.rewrite_hook.mark_rewrite(importspec)
try:
__import__(importspec)
except ImportError as e:
Expand Down
17 changes: 17 additions & 0 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ def test(check_first):
assert 0
result.stdout.fnmatch_lines([expected])

def test_rewrite_assertions_pytester_plugin(self, testdir):
"""
Assertions in the pytester plugin must also benefit from assertion
rewriting (#1920).
"""
testdir.makepyfile("""
pytest_plugins = ['pytester']
def test_dummy_failure(testdir): # how meta!
testdir.makepyfile('def test(): assert 0')
r = testdir.inline_run()
r.assertoutcome(passed=1)
""")
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines([
'*assert 1 == 0*',
])

@pytest.mark.parametrize('mode', ['plain', 'rewrite'])
def test_pytest_plugins_rewrite(self, testdir, mode):
contents = {
Expand Down

0 comments on commit e0c48b4

Please sign in to comment.