#1642 fix tests and config.py

This commit is contained in:
feuillemorte 2018-02-01 00:03:24 +03:00
parent ace772c743
commit 741b571f3b
2 changed files with 14 additions and 9 deletions

View File

@ -996,8 +996,6 @@ class Config(object):
self._parser.extra_info['rootdir'] = self.rootdir
self._parser.extra_info['inifile'] = self.inifile
self.invocation_dir = py.path.local()
if ns.rootdir:
self.invocation_dir = self.rootdir
self._parser.addini('addopts', 'extra command line options', 'args')
self._parser.addini('minversion', 'minimally required pytest version')
self._override_ini = ns.override_ini or ()

View File

@ -1,4 +1,7 @@
from __future__ import absolute_import, division, print_function
import os
import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED
@ -255,20 +258,24 @@ def test_sessionfinish_with_start(testdir):
assert res.ret == EXIT_NOTESTSCOLLECTED
def test_rootdir_option_arg(testdir):
@pytest.mark.parametrize("path", ["root", "{relative}/root", "{environment}/root"])
def test_rootdir_option_arg(testdir, path):
if 'relative' in path:
path = path.format(relative=os.getcwd())
if 'environment' in path:
os.environ['PY_ROOTDIR_PATH'] = os.getcwd()
path = path.format(environment='$PY_ROOTDIR_PATH')
rootdir = testdir.mkdir("root")
rootdir.mkdir("tests")
testdir.makepyfile("""
import os
def test_one():
assert os.path.isdir('.cache')
assert 1
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*AssertionError*"])
result = testdir.runpytest("--rootdir=root")
result.stdout.fnmatch_lines(["*1 passed*"])
result = testdir.runpytest("--rootdir={}".format(os.path.expandvars(path)))
result.stdout.fnmatch_lines(['*rootdir: {}/root, inifile:*'.format(os.getcwd()), "*1 passed*"])
def test_rootdir_wrong_option_arg(testdir):