tests for ini option cache_dir

This commit is contained in:
V.Kuznetsov 2017-07-07 13:07:33 +03:00
parent f471eef661
commit 7a9fc69435
1 changed files with 30 additions and 1 deletions

View File

@ -1,6 +1,6 @@
from __future__ import absolute_import, division, print_function
import sys
import py
import _pytest
import pytest
import os
@ -87,7 +87,36 @@ class TestNewAPI(object):
assert result.ret == 0
result.stdout.fnmatch_lines(["*1 passed*"])
def test_custom_rel_cache_dir(self, testdir):
rel_cache_dir = os.path.join('custom_cache_dir', 'subdir')
testdir.makeini("""
[pytest]
cache_dir = {cache_dir}
""".format(cache_dir=rel_cache_dir))
testdir.makepyfile(test_errored='def test_error():\n assert False')
testdir.runpytest()
assert testdir.tmpdir.join(rel_cache_dir).isdir()
def test_custom_abs_cache_dir(self, testdir, tmpdir_factory):
tmp = str(tmpdir_factory.mktemp('tmp'))
abs_cache_dir = os.path.join(tmp, 'custom_cache_dir')
testdir.makeini("""
[pytest]
cache_dir = {cache_dir}
""".format(cache_dir=abs_cache_dir))
testdir.makepyfile(test_errored='def test_error():\n assert False')
testdir.runpytest()
assert py.path.local(abs_cache_dir).isdir()
def test_custom_cache_dir_with_env_var(self, testdir, monkeypatch):
monkeypatch.setenv('env_var', 'custom_cache_dir')
testdir.makeini("""
[pytest]
cache_dir = {cache_dir}
""".format(cache_dir='$env_var'))
testdir.makepyfile(test_errored='def test_error():\n assert False')
testdir.runpytest()
assert testdir.tmpdir.join('custom_cache_dir').isdir()
def test_cache_reportheader(testdir):
testdir.makepyfile("""