#1642 Fix comments
This commit is contained in:
parent
936651702b
commit
3eb6cad222
|
@ -991,8 +991,8 @@ class Config(object):
|
||||||
|
|
||||||
def _initini(self, args):
|
def _initini(self, args):
|
||||||
ns, unknown_args = self._parser.parse_known_and_unknown_args(args, namespace=self.option.copy())
|
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,
|
||||||
r = determine_setup(ns.inifilename, ns.file_or_dir + unknown_args, warnfunc=self.warn, rootdir_cmd_arg=rootdir)
|
rootdir_cmd_arg=ns.rootdir or None)
|
||||||
self.rootdir, self.inifile, self.inicfg = r
|
self.rootdir, self.inifile, self.inicfg = r
|
||||||
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
|
||||||
|
@ -1348,7 +1348,7 @@ def determine_setup(inifile, args, warnfunc=None, rootdir_cmd_arg=None):
|
||||||
if is_fs_root:
|
if is_fs_root:
|
||||||
rootdir = ancestor
|
rootdir = ancestor
|
||||||
if rootdir_cmd_arg:
|
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)):
|
if not os.path.isdir(str(rootdir_abs_path)):
|
||||||
raise UsageError("Directory '{}' not found. Check your '--rootdir' option.".format(rootdir_abs_path))
|
raise UsageError("Directory '{}' not found. Check your '--rootdir' option.".format(rootdir_abs_path))
|
||||||
rootdir = 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
|
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.
|
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``
|
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
|
.. _`#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
|
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
|
||||||
|
@ -259,12 +257,10 @@ def test_sessionfinish_with_start(testdir):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("path", ["root", "{relative}/root", "{environment}/root"])
|
@pytest.mark.parametrize("path", ["root", "{relative}/root", "{environment}/root"])
|
||||||
def test_rootdir_option_arg(testdir, path):
|
def test_rootdir_option_arg(testdir, monkeypatch, path):
|
||||||
if 'relative' in path:
|
monkeypatch.setenv('PY_ROOTDIR_PATH', str(testdir.tmpdir))
|
||||||
path = path.format(relative=os.getcwd())
|
path = path.format(relative=str(testdir.tmpdir),
|
||||||
if 'environment' in path:
|
environment='$PY_ROOTDIR_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")
|
||||||
|
@ -274,8 +270,8 @@ def test_rootdir_option_arg(testdir, path):
|
||||||
assert 1
|
assert 1
|
||||||
""")
|
""")
|
||||||
|
|
||||||
result = testdir.runpytest("--rootdir={}".format(os.path.expandvars(path)))
|
result = testdir.runpytest("--rootdir={}".format(path))
|
||||||
result.stdout.fnmatch_lines(['*rootdir: {}/root, inifile:*'.format(os.getcwd()), "*1 passed*"])
|
result.stdout.fnmatch_lines(['*rootdir: {}/root, inifile:*'.format(testdir.tmpdir), "*1 passed*"])
|
||||||
|
|
||||||
|
|
||||||
def test_rootdir_wrong_option_arg(testdir):
|
def test_rootdir_wrong_option_arg(testdir):
|
||||||
|
|
Loading…
Reference in New Issue