|
29 | 29 | from _pytest.main import EXIT_INTERRUPTED |
30 | 30 | from _pytest.main import EXIT_OK |
31 | 31 | from _pytest.main import Session |
| 32 | +from _pytest.monkeypatch import MonkeyPatch |
32 | 33 | from _pytest.pathlib import Path |
33 | 34 |
|
34 | 35 | IGNORE_PAM = [ # filenames added when obtaining details about the current user |
@@ -469,8 +470,6 @@ def __init__(self, request, tmpdir_factory): |
469 | 470 | os.environ["PYTEST_DEBUG_TEMPROOT"] = str(self.test_tmproot) |
470 | 471 | os.environ.pop("TOX_ENV_DIR", None) # Ensure that it is not used for caching. |
471 | 472 | os.environ.pop("PYTEST_ADDOPTS", None) # Do not use outer options. |
472 | | - os.environ["HOME"] = str(self.tmpdir) # Do not load user config. |
473 | | - os.environ["USERPROFILE"] = os.environ["HOME"] |
474 | 473 | self.plugins = [] |
475 | 474 | self._cwd_snapshot = CwdSnapshot() |
476 | 475 | self._sys_path_snapshot = SysPathsSnapshot() |
@@ -788,6 +787,12 @@ def inline_run(self, *args, **kwargs): |
788 | 787 | """ |
789 | 788 | finalizers = [] |
790 | 789 | try: |
| 790 | + # Do not load user config. |
| 791 | + monkeypatch = MonkeyPatch() |
| 792 | + monkeypatch.setenv("HOME", str(self.tmpdir)) |
| 793 | + monkeypatch.setenv("USERPROFILE", str(self.tmpdir)) |
| 794 | + finalizers.append(monkeypatch.undo) |
| 795 | + |
791 | 796 | # When running pytest inline any plugins active in the main test |
792 | 797 | # process are already imported. So this disables the warning which |
793 | 798 | # will trigger to say they can no longer be rewritten, which is |
@@ -1018,6 +1023,9 @@ def popen(self, cmdargs, stdout, stderr, **kw): |
1018 | 1023 | env["PYTHONPATH"] = os.pathsep.join( |
1019 | 1024 | filter(None, [os.getcwd(), env.get("PYTHONPATH", "")]) |
1020 | 1025 | ) |
| 1026 | + # Do not load user config. |
| 1027 | + env["HOME"] = str(self.tmpdir) |
| 1028 | + env["USERPROFILE"] = env["HOME"] |
1021 | 1029 | kw["env"] = env |
1022 | 1030 |
|
1023 | 1031 | popen = subprocess.Popen( |
|
0 commit comments