Skip to content

Commit

Permalink
#1642 Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
feuillemorte committed Feb 1, 2018
1 parent 9366517 commit 3eb6cad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
6 changes: 3 additions & 3 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,8 @@ def pytest_load_initial_conftests(self, early_config):

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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions doc/en/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -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>`.
16 changes: 6 additions & 10 deletions testing/test_session.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import, division, print_function

import os

import pytest

from _pytest.main import EXIT_NOTESTSCOLLECTED
Expand Down Expand Up @@ -259,12 +257,10 @@ def pytest_sessionfinish():


@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")
Expand All @@ -274,8 +270,8 @@ def test_one():
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):
Expand Down

0 comments on commit 3eb6cad

Please sign in to comment.