From ac9c8fcdab8fcaa932100fed9dd67424609e310b Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Fri, 16 Dec 2016 15:29:08 +0100 Subject: [PATCH 1/4] Failing test for issue #2121 --- testing/test_assertrewrite.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 11b5ce051a4..8aee520b322 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -956,3 +956,17 @@ def test_ternary_display(): result = testdir.runpytest() result.stdout.fnmatch_lines('*E*assert True == ((False == True) == True)') + +class TestIssue2121(): + def test_simple(self, testdir): + testdir.tmpdir.join("tests/file.py").ensure().write(""" +def test_simple_failure(): + assert 1 + 1 == 3 +""") + testdir.tmpdir.join("pytest.ini").write(py.std.textwrap.dedent(""" + [pytest] + python_files = tests/**.py + """)) + + result = testdir.runpytest() + result.stdout.fnmatch_lines('*E*assert (1 + 1) == 3') From 021e843427c6f5e79ee4a5b47ef3015599292822 Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Sat, 17 Dec 2016 14:21:44 +0100 Subject: [PATCH 2/4] Fixed #2121 Use `py.path`s fnmatch. This fixes an issue where python_files handled properly when rewriting assertions. --- _pytest/assertion/rewrite.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index f7e255efd32..79943cc53b4 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -11,7 +11,6 @@ import struct import sys import types -from fnmatch import fnmatch import py from _pytest.assertion import util @@ -167,7 +166,7 @@ def _should_rewrite(self, name, fn_pypath, state): # latter might trigger an import to fnmatch.fnmatch # internally, which would cause this method to be # called recursively - if fnmatch(fn_pypath.basename, pat): + if fn_pypath.fnmatch(pat): state.trace("matched test file %r" % (fn,)) return True From 5de203195ce1a704f33a8d5c54dbe8996fe98b1e Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Sat, 17 Dec 2016 14:26:41 +0100 Subject: [PATCH 3/4] Add changelog for #2121 --- changelog/2121.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/2121.bugfix diff --git a/changelog/2121.bugfix b/changelog/2121.bugfix new file mode 100644 index 00000000000..15fd7706c58 --- /dev/null +++ b/changelog/2121.bugfix @@ -0,0 +1 @@ +Respect ``python_files`` in assertion rewriting. From c98ad2a0a0c8c1de278255cfec534dd928be2e85 Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Wed, 31 May 2017 08:32:51 +0200 Subject: [PATCH 4/4] Install py 1.4.33 that contains the fnmatch py.std import fix. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a71692c256b..751868c048e 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def has_environment_marker_support(): def main(): - install_requires = ['py>=1.4.29', 'setuptools'] # pluggy is vendored in _pytest.vendored_packages + install_requires = ['py>=1.4.33', 'setuptools'] # pluggy is vendored in _pytest.vendored_packages extras_require = {} if has_environment_marker_support(): extras_require[':python_version=="2.6"'] = ['argparse']