Skip to content

Commit

Permalink
Merge pull request #199 from blueyed/PY_IGNORE_IMPORTMISMATCH
Browse files Browse the repository at this point in the history
pyimport: add support for PY_IGNORE_IMPORTMISMATCH
  • Loading branch information
nicoddemus authored Oct 10, 2018
2 parents 796d5a0 + 59f8b93 commit 3c23d42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion py/_path/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ def pyimport(self, modname=None, ensuresyspath=True):
except py.error.ENOENT:
issame = False
if not issame:
raise self.ImportMismatchError(modname, modfile, self)
ignore = os.getenv('PY_IGNORE_IMPORTMISMATCH')
if ignore != '1':
raise self.ImportMismatchError(modname, modfile, self)
return mod
else:
try:
Expand Down
11 changes: 10 additions & 1 deletion testing/path/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,22 @@ def test_pyimport(self, path1):
assert obj.x == 42
assert obj.__name__ == 'execfile'

def test_pyimport_renamed_dir_creates_mismatch(self, tmpdir):
def test_pyimport_renamed_dir_creates_mismatch(self, tmpdir, monkeypatch):
p = tmpdir.ensure("a", "test_x123.py")
p.pyimport()
tmpdir.join("a").move(tmpdir.join("b"))
with pytest.raises(tmpdir.ImportMismatchError):
tmpdir.join("b", "test_x123.py").pyimport()

# Errors can be ignored.
monkeypatch.setenv('PY_IGNORE_IMPORTMISMATCH', '1')
tmpdir.join("b", "test_x123.py").pyimport()

# PY_IGNORE_IMPORTMISMATCH=0 does not ignore error.
monkeypatch.setenv('PY_IGNORE_IMPORTMISMATCH', '0')
with pytest.raises(tmpdir.ImportMismatchError):
tmpdir.join("b", "test_x123.py").pyimport()

def test_pyimport_messy_name(self, tmpdir):
# http://bitbucket.org/hpk42/py-trunk/issue/129
path = tmpdir.ensure('foo__init__.py')
Expand Down

0 comments on commit 3c23d42

Please sign in to comment.