#1642 Fix comments
This commit is contained in:
parent
936651702b
commit
3eb6cad222
|
@ -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
|
||||
|
|
|
@ -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 <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 <rootdir>`.
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue