#1642 fix tests and config.py
This commit is contained in:
parent
ace772c743
commit
741b571f3b
|
@ -996,8 +996,6 @@ class Config(object):
|
||||||
self._parser.extra_info['rootdir'] = self.rootdir
|
self._parser.extra_info['rootdir'] = self.rootdir
|
||||||
self._parser.extra_info['inifile'] = self.inifile
|
self._parser.extra_info['inifile'] = self.inifile
|
||||||
self.invocation_dir = py.path.local()
|
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('addopts', 'extra command line options', 'args')
|
||||||
self._parser.addini('minversion', 'minimally required pytest version')
|
self._parser.addini('minversion', 'minimally required pytest version')
|
||||||
self._override_ini = ns.override_ini or ()
|
self._override_ini = ns.override_ini or ()
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||||
|
@ -255,20 +258,24 @@ def test_sessionfinish_with_start(testdir):
|
||||||
assert res.ret == EXIT_NOTESTSCOLLECTED
|
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 = testdir.mkdir("root")
|
||||||
rootdir.mkdir("tests")
|
rootdir.mkdir("tests")
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import os
|
import os
|
||||||
def test_one():
|
def test_one():
|
||||||
assert os.path.isdir('.cache')
|
assert 1
|
||||||
""")
|
""")
|
||||||
|
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest("--rootdir={}".format(os.path.expandvars(path)))
|
||||||
result.stdout.fnmatch_lines(["*AssertionError*"])
|
result.stdout.fnmatch_lines(['*rootdir: {}/root, inifile:*'.format(os.getcwd()), "*1 passed*"])
|
||||||
|
|
||||||
result = testdir.runpytest("--rootdir=root")
|
|
||||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
|
||||||
|
|
||||||
|
|
||||||
def test_rootdir_wrong_option_arg(testdir):
|
def test_rootdir_wrong_option_arg(testdir):
|
||||||
|
|
Loading…
Reference in New Issue