diff --git a/CHANGELOG b/CHANGELOG index 7ef444b11..6e9ad833e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,8 @@ 2.7.0.dev (compared to 2.6.4) ----------------------------- -- fix issue463: raise specific error for 'parameterize' misspelling. +- fix issue435: make reload() work when assert rewriting is active. + Thanks Daniel Hahler. - fix issue616: conftest.py files and their contained fixutres are now properly considered for visibility, independently from the exact @@ -59,6 +60,8 @@ - allow to override parametrized fixtures with non-parametrized ones and vice versa (bubenkoff). +- fix issue463: raise specific error for 'parameterize' misspelling (pfctdayelise). + 2.6.4 ---------- diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 5e13a44c8..f965ba2c3 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -146,6 +146,12 @@ class AssertionRewritingHook(object): return self def load_module(self, name): + # If there is an existing module object named 'fullname' in + # sys.modules, the loader must use that existing module. (Otherwise, + # the reload() builtin will not work correctly.) + if name in sys.modules: + return sys.modules[name] + co, pyc = self.modules.pop(name) # I wish I could just call imp.load_compiled here, but __file__ has to # be set properly. In Python 3.2+, this all would be handled correctly diff --git a/_pytest/python.py b/_pytest/python.py index 596395062..5766768ed 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -778,7 +778,6 @@ class Metafunc(FuncargnamesCompatAttr): self.fixturenames = fixtureinfo.names_closure self._arg2fixturedefs = fixtureinfo.name2fixturedefs self.cls = cls - self.module = module self._calls = [] self._ids = py.builtin.set() diff --git a/doc/en/fixture.txt b/doc/en/fixture.txt index f2982dc9a..a72e0d90e 100644 --- a/doc/en/fixture.txt +++ b/doc/en/fixture.txt @@ -67,7 +67,6 @@ using it:: def test_ehlo(smtp): response, msg = smtp.ehlo() assert response == 250 - assert "merlinux" in msg assert 0 # for demo purposes Here, the ``test_ehlo`` needs the ``smtp`` fixture value. pytest diff --git a/doc/en/projects.txt b/doc/en/projects.txt index e603ea1eb..34a82b4c2 100644 --- a/doc/en/projects.txt +++ b/doc/en/projects.txt @@ -26,6 +26,7 @@ Here are some examples of projects using ``pytest`` (please send notes via :ref: `21000 tests `_ * the `MoinMoin `_ Wiki Engine * `sentry `_, realtime app-maintenance and exception tracking +* `Astropy `_ and `affiliated packages `_ * `tox `_, virtualenv/Hudson integration tool * `PIDA `_ framework for integrated development * `PyPM `_ ActiveState's package manager diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 56b4d3164..820fcabff 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -641,3 +641,27 @@ class TestAssertionRewriteHookDetails(object): pyc.write(contents[:strip_bytes], mode='wb') assert _read_pyc(source, str(pyc)) is None # no error + + def test_reload_is_same(self, testdir): + # A file that will be picked up during collecting. + testdir.tmpdir.join("file.py").ensure() + testdir.tmpdir.join("pytest.ini").write(py.std.textwrap.dedent(""" + [pytest] + python_files = *.py + """)) + + testdir.makepyfile(test_fun=""" + import sys + try: + from imp import reload + except ImportError: + pass + + def test_loader(): + import file + assert sys.modules["file"] is reload(file) + """) + result = testdir.runpytest('-s') + result.stdout.fnmatch_lines([ + "* 1 passed*", + ]) diff --git a/tox.ini b/tox.ini index 827125dfb..53bfb3f06 100644 --- a/tox.ini +++ b/tox.ini @@ -136,7 +136,7 @@ commands= minversion=2.0 plugins=pytester #--pyargs --doctest-modules --ignore=.tox -addopts= -rxsX -vl +addopts= -rxsX rsyncdirs=tox.ini pytest.py _pytest testing python_files=test_*.py *_test.py testing/*/*.py python_classes=Test Acceptance