From d784155fd2d306157bca115cb87c8eb3c488b746 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Wed, 17 Jan 2018 23:02:31 +0300 Subject: [PATCH 01/13] #1642 Add rootdir option --- AUTHORS | 1 + _pytest/main.py | 19 +++++++++++++++++++ testing/test_session.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/AUTHORS b/AUTHORS index 862378be9..d4447462c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -138,6 +138,7 @@ Ned Batchelder Neven Mundar Nicolas Delaby Oleg Pidsadnyi +Oleg Sushchenko Oliver Bestwalter Omar Kohl Omer Hadari diff --git a/_pytest/main.py b/_pytest/main.py index fce4f35f3..7fa86db17 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -33,6 +33,9 @@ def pytest_addoption(parser): parser.addini("testpaths", "directories to search for tests when no files or directories are given in the " "command line.", type="args", default=[]) + parser.addini("rootdir", "define root directory for tests. If this parameter defined command argument " + "'--rootdir' will not work", + type="args", default=[]) # parser.addini("dirpatterns", # "patterns specifying possible locations of test files", # type="linelist", default=["**/test_*.txt", @@ -53,6 +56,11 @@ def pytest_addoption(parser): group._addoption("--continue-on-collection-errors", action="store_true", default=False, dest="continue_on_collection_errors", help="Force test execution even if collection errors occur.") + group._addoption("--rootdir", action="store", + dest="rootdir", + help="Define root directory for tests. Can be relative path: 'root_dir', './root_dir', " + "'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: " + "'$HOME/root_dir'. If parameter 'rootdir' defined in *.ini file this argument will not work") group = parser.getgroup("collect", "collection") group.addoption('--collectonly', '--collect-only', action="store_true", @@ -283,6 +291,17 @@ class Session(nodes.FSCollector): self.trace = config.trace.root.get("collection") self._norecursepatterns = config.getini("norecursedirs") self.startdir = py.path.local() + + rootdir_ini = config.getini('rootdir') + self.rootdir = rootdir_ini[0] if rootdir_ini else config.option.rootdir + if self.rootdir: + rootdir_abs_path = py.path.local(self.rootdir) + if not os.path.isdir(str(rootdir_abs_path)): + raise UsageError("Directory '{}' not found. Check your '--rootdir' option.".format(rootdir_abs_path)) + config.invocation_dir = rootdir_abs_path + config.rootdir = rootdir_abs_path + sys.path.append(str(rootdir_abs_path)) + self.config.pluginmanager.register(self, name="session") def _makeid(self): diff --git a/testing/test_session.py b/testing/test_session.py index 9ec13f523..a8c5a408d 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -253,3 +253,35 @@ def test_sessionfinish_with_start(testdir): """) res = testdir.runpytest("--collect-only") assert res.ret == EXIT_NOTESTSCOLLECTED + + +def test_rootdir_option_arg(testdir): + rootdir = testdir.mkdir("root") + rootdir.join("spoon.py").write("spoon_number = 1") + testsdir = rootdir.mkdir("tests") + testsdir.join("test_one.py").write("from spoon import spoon_number\ndef test_one():\n assert spoon_number") + + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*No module named*spoon*"]) + + result = testdir.runpytest("--rootdir=root") + result.stdout.fnmatch_lines(["*1 passed*"]) + + +def test_rootdir_option_ini_file(testdir): + rootdir = testdir.mkdir("root") + rootdir.join("spoon.py").write("spoon_number = 1") + testsdir = rootdir.mkdir("tests") + testsdir.join("test_one.py").write("from spoon import spoon_number\ndef test_one():\n assert spoon_number") + + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*No module named*spoon*"]) + testdir.makeini(""" + [pytest] + rootdir=root + """) + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*1 passed*"]) + result = testdir.runpytest("--rootdir=ignored_argument") + print(result.stdout.str()) + result.stdout.fnmatch_lines(["*1 passed*"]) From 86f01967e160550468cfb4a5efce8a2d744ccabc Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Wed, 17 Jan 2018 23:05:22 +0300 Subject: [PATCH 02/13] #1642 Added changelog entry --- changelog/1642.trivial | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/1642.trivial diff --git a/changelog/1642.trivial b/changelog/1642.trivial new file mode 100644 index 000000000..a8f1f3fe4 --- /dev/null +++ b/changelog/1642.trivial @@ -0,0 +1 @@ +Added option `--rootdir` for command line and `rootdir` for *.ini file. Define root directory for tests. Can be relative path: 'root_dir', './root_dir', 'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: '$HOME/root_dir'. If parameter 'rootdir' defined in *.ini file this argument will not work. \ No newline at end of file From 4a18d7616078fa4a0c99b67501ac5e041faf5f21 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Wed, 17 Jan 2018 23:14:40 +0300 Subject: [PATCH 03/13] #1642 remove print --- testing/test_session.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/test_session.py b/testing/test_session.py index a8c5a408d..732a3af06 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -283,5 +283,4 @@ def test_rootdir_option_ini_file(testdir): result = testdir.runpytest() result.stdout.fnmatch_lines(["*1 passed*"]) result = testdir.runpytest("--rootdir=ignored_argument") - print(result.stdout.str()) result.stdout.fnmatch_lines(["*1 passed*"]) From a7c39c894b5b51f3efa9eb48de421b34bd069c26 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Wed, 17 Jan 2018 23:48:04 +0300 Subject: [PATCH 04/13] #1642 fix flake8 --- changelog/1642.trivial | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog/1642.trivial b/changelog/1642.trivial index a8f1f3fe4..87ed2913f 100644 --- a/changelog/1642.trivial +++ b/changelog/1642.trivial @@ -1 +1,3 @@ -Added option `--rootdir` for command line and `rootdir` for *.ini file. Define root directory for tests. Can be relative path: 'root_dir', './root_dir', 'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: '$HOME/root_dir'. If parameter 'rootdir' defined in *.ini file this argument will not work. \ No newline at end of file +Added option "--rootdir" for command line and "rootdir" for .ini file. Define root directory for tests. +Can be relative path: "root_dir", "./root_dir", "root_dir/another_dir/"; absolute path: "/home/user/root_dir"; +path with variables: "$HOME/root_dir". If parameter "rootdir" defined in .ini file this argument will not work. \ No newline at end of file From 83034bbd489aa3b5bfcf3efadc63c883b046ba1a Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Sat, 20 Jan 2018 22:30:01 +0300 Subject: [PATCH 05/13] #1642 Fix rootdir option --- _pytest/config.py | 13 +++++++++++-- _pytest/main.py | 15 +-------------- testing/test_session.py | 18 ------------------ 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index ce7468f72..14ed4d09b 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -990,11 +990,15 @@ class Config(object): def _initini(self, args): ns, unknown_args = self._parser.parse_known_and_unknown_args(args, namespace=self.option.copy()) - r = determine_setup(ns.inifilename, ns.file_or_dir + unknown_args, warnfunc=self.warn) + rootdir = ns.rootdir if ns.rootdir else None + r = determine_setup(ns.inifilename, ns.file_or_dir + unknown_args, warnfunc=self.warn, rootdir_cmd_arg=rootdir) self.rootdir, self.inifile, self.inicfg = r 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 + sys.path.append(str(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 () @@ -1323,7 +1327,7 @@ def get_dirs_from_args(args): ] -def determine_setup(inifile, args, warnfunc=None): +def determine_setup(inifile, args, warnfunc=None, rootdir_cmd_arg=None): dirs = get_dirs_from_args(args) if inifile: iniconfig = py.iniconfig.IniConfig(inifile) @@ -1346,6 +1350,11 @@ def determine_setup(inifile, args, warnfunc=None): is_fs_root = os.path.splitdrive(str(rootdir))[1] == '/' if is_fs_root: rootdir = ancestor + if rootdir_cmd_arg: + rootdir_abs_path = py.path.local(rootdir_cmd_arg) + if not os.path.isdir(str(rootdir_abs_path)): + raise UsageError("Directory '{}' not found. Check your '--rootdir' option.".format(rootdir_abs_path)) + rootdir = rootdir_abs_path return rootdir, inifile, inicfg or {} diff --git a/_pytest/main.py b/_pytest/main.py index 7fa86db17..ed70bfb31 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -33,9 +33,6 @@ def pytest_addoption(parser): parser.addini("testpaths", "directories to search for tests when no files or directories are given in the " "command line.", type="args", default=[]) - parser.addini("rootdir", "define root directory for tests. If this parameter defined command argument " - "'--rootdir' will not work", - type="args", default=[]) # parser.addini("dirpatterns", # "patterns specifying possible locations of test files", # type="linelist", default=["**/test_*.txt", @@ -60,7 +57,7 @@ def pytest_addoption(parser): dest="rootdir", help="Define root directory for tests. Can be relative path: 'root_dir', './root_dir', " "'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: " - "'$HOME/root_dir'. If parameter 'rootdir' defined in *.ini file this argument will not work") + "'$HOME/root_dir'.") group = parser.getgroup("collect", "collection") group.addoption('--collectonly', '--collect-only', action="store_true", @@ -292,16 +289,6 @@ class Session(nodes.FSCollector): self._norecursepatterns = config.getini("norecursedirs") self.startdir = py.path.local() - rootdir_ini = config.getini('rootdir') - self.rootdir = rootdir_ini[0] if rootdir_ini else config.option.rootdir - if self.rootdir: - rootdir_abs_path = py.path.local(self.rootdir) - if not os.path.isdir(str(rootdir_abs_path)): - raise UsageError("Directory '{}' not found. Check your '--rootdir' option.".format(rootdir_abs_path)) - config.invocation_dir = rootdir_abs_path - config.rootdir = rootdir_abs_path - sys.path.append(str(rootdir_abs_path)) - self.config.pluginmanager.register(self, name="session") def _makeid(self): diff --git a/testing/test_session.py b/testing/test_session.py index 732a3af06..5c1b9918f 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -266,21 +266,3 @@ def test_rootdir_option_arg(testdir): result = testdir.runpytest("--rootdir=root") result.stdout.fnmatch_lines(["*1 passed*"]) - - -def test_rootdir_option_ini_file(testdir): - rootdir = testdir.mkdir("root") - rootdir.join("spoon.py").write("spoon_number = 1") - testsdir = rootdir.mkdir("tests") - testsdir.join("test_one.py").write("from spoon import spoon_number\ndef test_one():\n assert spoon_number") - - result = testdir.runpytest() - result.stdout.fnmatch_lines(["*No module named*spoon*"]) - testdir.makeini(""" - [pytest] - rootdir=root - """) - result = testdir.runpytest() - result.stdout.fnmatch_lines(["*1 passed*"]) - result = testdir.runpytest("--rootdir=ignored_argument") - result.stdout.fnmatch_lines(["*1 passed*"]) From a7066ba8373f9fcfa424d698a304294f978a7c14 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 23 Jan 2018 17:31:07 -0200 Subject: [PATCH 06/13] Update formatting in the CHANGELOG --- changelog/1642.trivial | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/changelog/1642.trivial b/changelog/1642.trivial index 87ed2913f..a6acc5565 100644 --- a/changelog/1642.trivial +++ b/changelog/1642.trivial @@ -1,3 +1 @@ -Added option "--rootdir" for command line and "rootdir" for .ini file. Define root directory for tests. -Can be relative path: "root_dir", "./root_dir", "root_dir/another_dir/"; absolute path: "/home/user/root_dir"; -path with variables: "$HOME/root_dir". If parameter "rootdir" defined in .ini file this argument will not work. \ No newline at end of file +Add ``--rootdir`` command-line option to override the rules for discovering the root directory. See `customize `_ in the documentation for details. From 0cfa975930f450537543e8d8334f4518f63fba56 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 25 Jan 2018 15:57:04 +0300 Subject: [PATCH 07/13] #1642 Fix tests --- testing/test_session.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/testing/test_session.py b/testing/test_session.py index 5c1b9918f..798e1d9cb 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -257,12 +257,24 @@ def test_sessionfinish_with_start(testdir): def test_rootdir_option_arg(testdir): rootdir = testdir.mkdir("root") - rootdir.join("spoon.py").write("spoon_number = 1") - testsdir = rootdir.mkdir("tests") - testsdir.join("test_one.py").write("from spoon import spoon_number\ndef test_one():\n assert spoon_number") + rootdir.mkdir("tests") + testdir.makepyfile(""" + import os + def test_one(): + assert os.path.isdir('.cache') + """) result = testdir.runpytest() - result.stdout.fnmatch_lines(["*No module named*spoon*"]) + result.stdout.fnmatch_lines(["*AssertionError*"]) result = testdir.runpytest("--rootdir=root") result.stdout.fnmatch_lines(["*1 passed*"]) + + +def test_rootdir_wrong_option_arg(testdir): + rootdir = testdir.mkdir("root") + testsdir = rootdir.mkdir("tests") + testsdir.join("test_one.py").write("def test_one():\n assert 1") + + result = testdir.runpytest("--rootdir=wrong_dir") + result.stderr.fnmatch_lines(["*Directory *wrong_dir* not found. Check your '--rootdir' option.*"]) From 503e00f7ffca1b2805abe97b4a9f63870a98eaaa Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 25 Jan 2018 15:57:29 +0300 Subject: [PATCH 08/13] #1642 Remove adding rootdir to sys path --- _pytest/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/_pytest/config.py b/_pytest/config.py index 14ed4d09b..dfdbeab3f 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -998,7 +998,6 @@ class Config(object): self.invocation_dir = py.path.local() if ns.rootdir: self.invocation_dir = self.rootdir - sys.path.append(str(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 () From 3a004a4507e57aa199884183ab735e501121130d Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 25 Jan 2018 19:46:22 +0300 Subject: [PATCH 09/13] added rootdir description to customize.rst --- doc/en/customize.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/en/customize.rst b/doc/en/customize.rst index 8133704a5..4101ca283 100644 --- a/doc/en/customize.rst +++ b/doc/en/customize.rst @@ -331,3 +331,9 @@ Builtin configuration file options # content of pytest.ini [pytest] console_output_style = classic + +.. confval:: rootdir + + Sets a :ref:`rootdir ` directory. Directory may be relative or absolute path. + Additionally path may contain environment variables, that will be expanded. + For more information about rootdir please refer to :ref:`rootdir `. From 741b571f3b6cd1bcfec6db7ba90f112cd5bbc8d1 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 1 Feb 2018 00:03:24 +0300 Subject: [PATCH 10/13] #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): From 936651702bc14ed785dc40e364feed7f48892f1a Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 1 Feb 2018 00:27:48 +0300 Subject: [PATCH 11/13] #1642 Fix tests --- testing/test_session.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testing/test_session.py b/testing/test_session.py index 5f85c6309..ddebe2f67 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -279,9 +279,11 @@ def test_rootdir_option_arg(testdir, path): def test_rootdir_wrong_option_arg(testdir): - rootdir = testdir.mkdir("root") - testsdir = rootdir.mkdir("tests") - testsdir.join("test_one.py").write("def test_one():\n assert 1") + testdir.makepyfile(""" + import os + def test_one(): + assert 1 + """) result = testdir.runpytest("--rootdir=wrong_dir") result.stderr.fnmatch_lines(["*Directory *wrong_dir* not found. Check your '--rootdir' option.*"]) From 3eb6cad222b3c5eb5d060f19faf94d046b95dfde Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 1 Feb 2018 11:20:37 +0300 Subject: [PATCH 12/13] #1642 Fix comments --- _pytest/config.py | 6 +++--- doc/en/customize.rst | 9 +++------ testing/test_session.py | 16 ++++++---------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index 986f46ff0..a9b071b6f 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -991,8 +991,8 @@ class Config(object): def _initini(self, args): ns, unknown_args = self._parser.parse_known_and_unknown_args(args, namespace=self.option.copy()) - rootdir = ns.rootdir if ns.rootdir else None - r = determine_setup(ns.inifilename, ns.file_or_dir + unknown_args, warnfunc=self.warn, rootdir_cmd_arg=rootdir) + r = determine_setup(ns.inifilename, ns.file_or_dir + unknown_args, warnfunc=self.warn, + rootdir_cmd_arg=ns.rootdir or None) self.rootdir, self.inifile, self.inicfg = r self._parser.extra_info['rootdir'] = self.rootdir self._parser.extra_info['inifile'] = self.inifile @@ -1348,7 +1348,7 @@ def determine_setup(inifile, args, warnfunc=None, rootdir_cmd_arg=None): if is_fs_root: rootdir = ancestor if rootdir_cmd_arg: - rootdir_abs_path = py.path.local(rootdir_cmd_arg) + rootdir_abs_path = py.path.local(os.path.expandvars(rootdir_cmd_arg)) if not os.path.isdir(str(rootdir_abs_path)): raise UsageError("Directory '{}' not found. Check your '--rootdir' option.".format(rootdir_abs_path)) rootdir = rootdir_abs_path diff --git a/doc/en/customize.rst b/doc/en/customize.rst index 1f0d8bb48..7aa1641fa 100644 --- a/doc/en/customize.rst +++ b/doc/en/customize.rst @@ -38,6 +38,9 @@ Here's a summary what ``pytest`` uses ``rootdir`` for: Important to emphasize that ``rootdir`` is **NOT** used to modify ``sys.path``/``PYTHONPATH`` or influence how modules are imported. See :ref:`pythonpath` for more details. +``--rootdir=path`` command line option sets a ``rootdir`` directory. Directory may be relative or absolute path. +Additionally path may contain environment variables, that will be expanded. + Finding the ``rootdir`` ~~~~~~~~~~~~~~~~~~~~~~~ @@ -371,9 +374,3 @@ passed multiple times. The expected format is ``name=value``. For example:: .. _`#3155`: https://github.com/pytest-dev/pytest/issues/3155 - -.. confval:: rootdir - - Sets a :ref:`rootdir ` directory. Directory may be relative or absolute path. - Additionally path may contain environment variables, that will be expanded. - For more information about rootdir please refer to :ref:`rootdir `. diff --git a/testing/test_session.py b/testing/test_session.py index ddebe2f67..68534b102 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, division, print_function -import os - import pytest from _pytest.main import EXIT_NOTESTSCOLLECTED @@ -259,12 +257,10 @@ def test_sessionfinish_with_start(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') +def test_rootdir_option_arg(testdir, monkeypatch, path): + monkeypatch.setenv('PY_ROOTDIR_PATH', str(testdir.tmpdir)) + path = path.format(relative=str(testdir.tmpdir), + environment='$PY_ROOTDIR_PATH') rootdir = testdir.mkdir("root") rootdir.mkdir("tests") @@ -274,8 +270,8 @@ def test_rootdir_option_arg(testdir, path): assert 1 """) - result = testdir.runpytest("--rootdir={}".format(os.path.expandvars(path))) - result.stdout.fnmatch_lines(['*rootdir: {}/root, inifile:*'.format(os.getcwd()), "*1 passed*"]) + result = testdir.runpytest("--rootdir={}".format(path)) + result.stdout.fnmatch_lines(['*rootdir: {}/root, inifile:*'.format(testdir.tmpdir), "*1 passed*"]) def test_rootdir_wrong_option_arg(testdir): From 37d836d754eb8e20540ff1a16da76edee9a7adda Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 1 Feb 2018 19:34:15 -0200 Subject: [PATCH 13/13] Reword docs slightly --- doc/en/customize.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/en/customize.rst b/doc/en/customize.rst index 7aa1641fa..f819c5974 100644 --- a/doc/en/customize.rst +++ b/doc/en/customize.rst @@ -38,8 +38,9 @@ Here's a summary what ``pytest`` uses ``rootdir`` for: Important to emphasize that ``rootdir`` is **NOT** used to modify ``sys.path``/``PYTHONPATH`` or influence how modules are imported. See :ref:`pythonpath` for more details. -``--rootdir=path`` command line option sets a ``rootdir`` directory. Directory may be relative or absolute path. -Additionally path may contain environment variables, that will be expanded. +``--rootdir=path`` command-line option can be used to force a specific directory. +The directory passed may contain environment variables when it is used in conjunction +with ``addopts`` in a ``pytest.ini`` file. Finding the ``rootdir`` ~~~~~~~~~~~~~~~~~~~~~~~