From 3eb6cad222b3c5eb5d060f19faf94d046b95dfde Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Thu, 1 Feb 2018 11:20:37 +0300 Subject: [PATCH] #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):