diff --git a/changelog/4851.bugfix.rst b/changelog/4851.bugfix.rst new file mode 100644 index 00000000000..7b532af3ee9 --- /dev/null +++ b/changelog/4851.bugfix.rst @@ -0,0 +1 @@ +pytester unsets ``PYTEST_ADDOPTS`` now to not use outer options with ``testdir.runpytest()``. diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index fae243a50ca..4aab1a3eb01 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -509,6 +509,7 @@ def __init__(self, request, tmpdir_factory): self.test_tmproot = tmpdir_factory.mktemp("tmp-" + name, numbered=True) os.environ["PYTEST_DEBUG_TEMPROOT"] = str(self.test_tmproot) os.environ.pop("TOX_ENV_DIR", None) # Ensure that it is not used for caching. + os.environ.pop("PYTEST_ADDOPTS", None) # Do not use outer options. self.plugins = [] self._cwd_snapshot = CwdSnapshot() self._sys_path_snapshot = SysPathsSnapshot()