diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index f7e255efd..79943cc53 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -11,7 +11,6 @@ import re import struct import sys import types -from fnmatch import fnmatch import py from _pytest.assertion import util @@ -167,7 +166,7 @@ class AssertionRewritingHook(object): # 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 diff --git a/changelog/2121.bugfix b/changelog/2121.bugfix new file mode 100644 index 000000000..15fd7706c --- /dev/null +++ b/changelog/2121.bugfix @@ -0,0 +1 @@ +Respect ``python_files`` in assertion rewriting. diff --git a/setup.py b/setup.py index a71692c25..751868c04 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'] diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 11b5ce051..8aee520b3 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -956,3 +956,17 @@ class TestIssue925(object): 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')