summaryrefslogtreecommitdiff
path: root/testing/test_cacheprovider.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2018-10-30 22:35:09 +0100
committerDaniel Hahler <git@thequod.de>2018-11-09 05:29:28 +0100
commita507f44465566c1aadbfcc0514dcd2bec8e8847b (patch)
tree8575c12012da59fec10dd715649e02c93ccbaf06 /testing/test_cacheprovider.py
parent6c0605724252e939289e77d2a2290adac609eee7 (diff)
downloadpytest-a507f44465566c1aadbfcc0514dcd2bec8e8847b.tar.gz
cache_dir: use $TOX_ENV_DIR/ prefix if set
Fixes https://github.com/pytest-dev/pytest/issues/4270
Diffstat (limited to 'testing/test_cacheprovider.py')
-rw-r--r--testing/test_cacheprovider.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py
index cd888dce1..55090a2f6 100644
--- a/testing/test_cacheprovider.py
+++ b/testing/test_cacheprovider.py
@@ -14,6 +14,17 @@ import pytest
pytest_plugins = ("pytester",)
+@pytest.fixture(scope="module", autouse=True)
+def handle_env():
+ """Ensure env is like most of the tests expect it, i.e. not using tox."""
+ orig_env = os.environ.pop("TOX_ENV_DIR", None)
+
+ yield
+
+ if orig_env is not None:
+ os.environ["TOX_ENV_DIR"] = orig_env
+
+
class TestNewAPI(object):
def test_config_cache_makedir(self, testdir):
testdir.makeini("[pytest]")
@@ -148,15 +159,17 @@ class TestNewAPI(object):
assert testdir.tmpdir.join("custom_cache_dir").isdir()
-def test_cache_reportheader(testdir):
- testdir.makepyfile(
- """
- def test_hello():
- pass
- """
- )
+@pytest.mark.parametrize("env", ((), ("TOX_ENV_DIR", "/tox_env_dir")))
+def test_cache_reportheader(env, testdir, monkeypatch):
+ testdir.makepyfile("""def test_foo(): pass""")
+ if env:
+ monkeypatch.setenv(*env)
+ expected = os.path.join(env[1], ".pytest_cache")
+ else:
+ monkeypatch.delenv("TOX_ENV_DIR", raising=False)
+ expected = ".pytest_cache"
result = testdir.runpytest("-v")
- result.stdout.fnmatch_lines(["cachedir: .pytest_cache"])
+ result.stdout.fnmatch_lines(["cachedir: %s" % expected])
def test_cache_reportheader_external_abspath(testdir, tmpdir_factory):