From 678750c8f873f32a9a09987463805fe59c829e54 Mon Sep 17 00:00:00 2001 From: Marcin Bachry Date: Sun, 21 Aug 2016 22:07:18 +0200 Subject: [PATCH 1/3] Fix importer call --- _pytest/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/main.py b/_pytest/main.py index 48f5bb6f2e2..5771a169999 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -687,7 +687,7 @@ def _tryconvertpyarg(self, x): # This method is sometimes invoked when AssertionRewritingHook, which # does not define a get_filename method, is already in place: try: - path = loader.get_filename() + path = loader.get_filename(x) except AttributeError: # Retrieve path from AssertionRewritingHook: path = loader.modules[x][0].co_filename From 6a8160b3181f6f0fd0bc8afa40eca0a8913d4c29 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 22 Aug 2016 17:54:17 -0300 Subject: [PATCH 2/3] Add acceptance test for module loader Related to #1837 --- testing/acceptance_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 82b131dccaf..b03f7fe4c36 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -763,3 +763,21 @@ def test_setup_function(self, testdir): * call *test_1* """) + +def test_zipimport_hook(testdir, tmpdir): + """Test package loader is being used correctly (see #1837).""" + zipapp = pytest.importorskip('zipapp') + testdir.tmpdir.join('app').ensure(dir=1) + testdir.makepyfile(**{ + 'app/foo.py': """ + import pytest + def main(): + pytest.main(['--pyarg', 'foo']) + """, + }) + target = tmpdir.join('foo.zip') + zipapp.create_archive(str(testdir.tmpdir.join('app')), str(target), main='foo:main') + result = testdir.runpython(target) + assert result.ret == 0 + result.stderr.fnmatch_lines(['*not found*foo*']) + assert 'INTERNALERROR>' not in result.stdout.str() From b54ea74d4d0f1886c65a933f4c2215f224287cf1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 22 Aug 2016 17:59:42 -0300 Subject: [PATCH 3/3] Update AUTHORS and CHANGELOG for #1837 --- AUTHORS | 1 + CHANGELOG.rst | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/AUTHORS b/AUTHORS index 40f77e0832d..b1e8f7f4c30 100644 --- a/AUTHORS +++ b/AUTHORS @@ -81,6 +81,7 @@ Lukas Bednar Maciek Fijalkowski Maho Marc Schlaich +Marcin Bachry Mark Abramowitz Markus Unterwaditzer Martijn Faassen diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 13c61c9239d..d571a2bf3db 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,11 +6,15 @@ * +* Fix loader error when running ``pytest`` embedded in a zipfile. + Thanks `@mbachry`_ for the PR. + * * +.. _@mbachry: https://github.com/mbachry .. _#1822: https://github.com/pytest-dev/pytest/issues/1822