diff --git a/CHANGELOG b/CHANGELOG index 8aab63ce4..614169950 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Changes between 2.1.1 and [NEXT VERSION] ---------------------------------------- +- fix issue68 / packages now work with assertion rewriting - fix issue66: use different assertion rewriting caches when the -O option is passed Changes between 2.1.0 and 2.1.1 diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 8d850433b..a82871669 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -77,7 +77,7 @@ class AssertionRewritingHook(object): # Don't know what this is. return None else: - fn = os.path.join(pth, name + ".py") + fn = os.path.join(pth, name.rpartition(".")[2] + ".py") fn_pypath = py.path.local(fn) # Is this a test file? if not sess.isinitpath(fn): diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 8c322c09e..bf5ea5179 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -340,3 +340,12 @@ def test_optimized(): assert testdir.runpybin("py.test", tmp).ret == 0 monkeypatch.undo() assert testdir.runpybin("py.test", tmp).ret == 1 + + def test_package(self, testdir): + pkg = testdir.tmpdir.join("pkg") + pkg.mkdir() + pkg.join("__init__.py").ensure() + pkg.join("test_blah.py").write(""" +def test_rewritten(): + assert "@py_builtins" in globals()""") + assert testdir.runpytest().ret == 0