From c629f6b18b076bd60fc8e28bec95c9e5f141687d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 4 Mar 2015 16:21:27 +0100 Subject: [PATCH 1/4] Fix `reload()` with modules handled via `python_files` If a module exists in `sys.modules` already, `load_module` has to return it. Fixes https://bitbucket.org/pytest-dev/pytest/issue/435 --HG-- branch : fix-reload --- _pytest/assertion/rewrite.py | 6 ++++++ testing/test_assertrewrite.py | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) 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/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*", + ]) From 25a4d7d882d159e0fe06a5346299367bcfc481e4 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 17 Mar 2015 13:19:26 +0100 Subject: [PATCH 2/4] remove default-verbose running --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 03c3930734df267f2647b9aba5d9c017a221fcc8 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 17 Mar 2015 13:21:44 +0100 Subject: [PATCH 3/4] add a project someone reported a while ago --- doc/en/fixture.txt | 1 - doc/en/projects.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) 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 From 65ca5542302f303b82e5854a5964dcfbfb048563 Mon Sep 17 00:00:00 2001 From: tigeraniya Date: Mon, 23 Mar 2015 20:47:34 +0530 Subject: [PATCH 4/4] duplicate assignment --- _pytest/python.py | 1 - 1 file changed, 1 deletion(-) diff --git a/_pytest/python.py b/_pytest/python.py index 318038771..81a6373d4 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -774,7 +774,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()