Skip to content

Commit d99ceb1

Browse files
authored
Merge pull request #1844 from nicoddemus/importer-error
Importer loader error
2 parents c3148d1 + b54ea74 commit d99ceb1

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Lukas Bednar
8080
Maciek Fijalkowski
8181
Maho
8282
Marc Schlaich
83+
Marcin Bachry
8384
Mark Abramowitz
8485
Markus Unterwaditzer
8586
Martijn Faassen

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
*
88

9+
* Fix loader error when running ``pytest`` embedded in a zipfile.
10+
Thanks `@mbachry`_ for the PR.
11+
912
*
1013

1114
*
1215

1316

17+
.. _@mbachry: https://github.com/mbachry
1418

1519
.. _#1822: https://github.com/pytest-dev/pytest/issues/1822
1620

_pytest/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def _tryconvertpyarg(self, x):
687687
# This method is sometimes invoked when AssertionRewritingHook, which
688688
# does not define a get_filename method, is already in place:
689689
try:
690-
path = loader.get_filename()
690+
path = loader.get_filename(x)
691691
except AttributeError:
692692
# Retrieve path from AssertionRewritingHook:
693693
path = loader.modules[x][0].co_filename

testing/acceptance_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,21 @@ def test_setup_function(self, testdir):
763763
* call *test_1*
764764
""")
765765

766+
767+
def test_zipimport_hook(testdir, tmpdir):
768+
"""Test package loader is being used correctly (see #1837)."""
769+
zipapp = pytest.importorskip('zipapp')
770+
testdir.tmpdir.join('app').ensure(dir=1)
771+
testdir.makepyfile(**{
772+
'app/foo.py': """
773+
import pytest
774+
def main():
775+
pytest.main(['--pyarg', 'foo'])
776+
""",
777+
})
778+
target = tmpdir.join('foo.zip')
779+
zipapp.create_archive(str(testdir.tmpdir.join('app')), str(target), main='foo:main')
780+
result = testdir.runpython(target)
781+
assert result.ret == 0
782+
result.stderr.fnmatch_lines(['*not found*foo*'])
783+
assert 'INTERNALERROR>' not in result.stdout.str()

0 commit comments

Comments
 (0)