Merge pull request #3667 from asottile/avoid_sys_path_pollution_742

Use -mpytest when invoking pytest in pytester
This commit is contained in:
Bruno Oliveira 2018-07-08 11:51:16 -03:00 committed by GitHub
commit d4faa4056b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 8 deletions

1
changelog/742.bugfix.rst Normal file
View File

@ -0,0 +1 @@
Invoke pytest using ``-mpytest`` so ``sys.path`` does not get polluted by packages installed in ``site-packages``.

View File

@ -23,11 +23,6 @@ from _pytest.main import Session, EXIT_OK
from _pytest.assertion.rewrite import AssertionRewritingHook
PYTEST_FULLPATH = os.path.abspath(pytest.__file__.rstrip("oc")).replace(
"$py.class", ".py"
)
IGNORE_PAM = [ # filenames added when obtaining details about the current user
u"/var/lib/sss/mc/passwd"
]
@ -1029,9 +1024,7 @@ class Testdir(object):
print("couldn't print to %s because of encoding" % (fp,))
def _getpytestargs(self):
# we cannot use `(sys.executable, script)` because on Windows the
# script is e.g. `pytest.exe`
return (sys.executable, PYTEST_FULLPATH) # noqa
return (sys.executable, "-mpytest")
def runpython(self, script):
"""Run a python script using sys.executable as interpreter.

View File

@ -394,3 +394,8 @@ class TestSysPathsSnapshot(object):
assert getattr(sys, path_type) == original_data
assert getattr(sys, other_path_type) is original_other
assert getattr(sys, other_path_type) == original_other_data
def test_testdir_subprocess(testdir):
testfile = testdir.makepyfile("def test_one(): pass")
assert testdir.runpytest_subprocess(testfile).ret == 0