|
14 | 14 | pytest_plugins = ("pytester",)
|
15 | 15 |
|
16 | 16 |
|
| 17 | +@pytest.fixture(scope="module", autouse=True) |
| 18 | +def handle_env(): |
| 19 | + """Ensure env is like most of the tests expect it, i.e. not using tox.""" |
| 20 | + orig_env = os.environ.pop("TOX_ENV_DIR", None) |
| 21 | + |
| 22 | + yield |
| 23 | + |
| 24 | + if orig_env is not None: |
| 25 | + os.environ["TOX_ENV_DIR"] = orig_env |
| 26 | + |
| 27 | + |
17 | 28 | class TestNewAPI(object):
|
18 | 29 | def test_config_cache_makedir(self, testdir):
|
19 | 30 | testdir.makeini("[pytest]")
|
@@ -148,15 +159,17 @@ def test_custom_cache_dir_with_env_var(self, testdir, monkeypatch):
|
148 | 159 | assert testdir.tmpdir.join("custom_cache_dir").isdir()
|
149 | 160 |
|
150 | 161 |
|
151 |
| -def test_cache_reportheader(testdir): |
152 |
| - testdir.makepyfile( |
153 |
| - """ |
154 |
| - def test_hello(): |
155 |
| - pass |
156 |
| - """ |
157 |
| - ) |
| 162 | +@pytest.mark.parametrize("env", ((), ("TOX_ENV_DIR", "/tox_env_dir"))) |
| 163 | +def test_cache_reportheader(env, testdir, monkeypatch): |
| 164 | + testdir.makepyfile("""def test_foo(): pass""") |
| 165 | + if env: |
| 166 | + monkeypatch.setenv(*env) |
| 167 | + expected = os.path.join(env[1], ".pytest_cache") |
| 168 | + else: |
| 169 | + monkeypatch.delenv("TOX_ENV_DIR", raising=False) |
| 170 | + expected = ".pytest_cache" |
158 | 171 | result = testdir.runpytest("-v")
|
159 |
| - result.stdout.fnmatch_lines(["cachedir: .pytest_cache"]) |
| 172 | + result.stdout.fnmatch_lines(["cachedir: %s" % expected]) |
160 | 173 |
|
161 | 174 |
|
162 | 175 | def test_cache_reportheader_external_abspath(testdir, tmpdir_factory):
|
|
0 commit comments