From 741b571f3b6cd1bcfec6db7ba90f112cd5bbc8d1 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 1 Feb 2018 00:03:24 +0300 Subject: [PATCH] #1642 fix tests and config.py --- _pytest/config.py | 2 -- testing/test_session.py | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index dfdbeab3f..59858f6e8 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -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 () diff --git a/testing/test_session.py b/testing/test_session.py index 798e1d9cb..5f85c6309 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -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):