Merge pull request #1844 from nicoddemus/importer-error

Importer loader error
This commit is contained in:
Bruno Oliveira 2016-08-22 20:47:25 -03:00 committed by GitHub
commit d99ceb1218
4 changed files with 24 additions and 1 deletions

View File

@ -80,6 +80,7 @@ Lukas Bednar
Maciek Fijalkowski
Maho
Marc Schlaich
Marcin Bachry
Mark Abramowitz
Markus Unterwaditzer
Martijn Faassen

View File

@ -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

View File

@ -687,7 +687,7 @@ class Session(FSCollector):
# 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

View File

@ -763,3 +763,21 @@ class TestDurationWithFixture:
* 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()