Skip to content

Handle python_files correctly in assertion rewrite #2140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions _pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import struct
import sys
import types
from fnmatch import fnmatch

import py
from _pytest.assertion import util
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions changelog/2121.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Respect ``python_files`` in assertion rewriting.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
14 changes: 14 additions & 0 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')