Merge pull request #3667 from asottile/avoid_sys_path_pollution_742
Use -mpytest when invoking pytest in pytester
This commit is contained in:
commit
d4faa4056b
|
@ -0,0 +1 @@
|
|||
Invoke pytest using ``-mpytest`` so ``sys.path`` does not get polluted by packages installed in ``site-packages``.
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue