2017-03-17 09:21:30 +08:00
|
|
|
from __future__ import absolute_import, division, print_function
|
2017-11-29 00:29:52 +08:00
|
|
|
import sys
|
2017-12-27 11:47:26 +08:00
|
|
|
import textwrap
|
2017-07-17 07:25:09 +08:00
|
|
|
import pytest
|
2009-03-17 05:17:14 +08:00
|
|
|
|
2015-11-27 22:43:01 +08:00
|
|
|
import _pytest._code
|
2018-06-05 16:20:36 +08:00
|
|
|
from _pytest.config.findpaths import getcfg, get_common_ancestor, determine_setup
|
|
|
|
from _pytest.config import _iter_rewritable_modules
|
2015-07-05 01:42:22 +08:00
|
|
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestParseIni(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"section, filename", [("pytest", "pytest.ini"), ("tool:pytest", "setup.cfg")]
|
|
|
|
)
|
2016-08-17 08:30:07 +08:00
|
|
|
def test_getcfg_and_config(self, testdir, tmpdir, section, filename):
|
2010-10-28 01:35:27 +08:00
|
|
|
sub = tmpdir.mkdir("sub")
|
|
|
|
sub.chdir()
|
2018-05-23 22:48:46 +08:00
|
|
|
tmpdir.join(filename).write(
|
2018-08-24 00:06:17 +08:00
|
|
|
textwrap.dedent(
|
|
|
|
"""\
|
|
|
|
[{section}]
|
|
|
|
name = value
|
|
|
|
""".format(
|
2018-05-23 22:48:46 +08:00
|
|
|
section=section
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-08-17 08:30:07 +08:00
|
|
|
rootdir, inifile, cfg = getcfg([sub])
|
2018-05-23 22:48:46 +08:00
|
|
|
assert cfg["name"] == "value"
|
2011-11-08 02:08:41 +08:00
|
|
|
config = testdir.parseconfigure(sub)
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.inicfg["name"] == "value"
|
2010-10-28 01:35:27 +08:00
|
|
|
|
2016-08-17 08:30:07 +08:00
|
|
|
def test_getcfg_empty_path(self):
|
|
|
|
"""correctly handle zero length arguments (a la pytest '')"""
|
2018-05-23 22:48:46 +08:00
|
|
|
getcfg([""])
|
2011-09-26 05:26:49 +08:00
|
|
|
|
2015-01-29 18:52:01 +08:00
|
|
|
def test_append_parse_args(self, testdir, tmpdir, monkeypatch):
|
2018-05-23 22:48:46 +08:00
|
|
|
monkeypatch.setenv("PYTEST_ADDOPTS", '--color no -rs --tb="short"')
|
|
|
|
tmpdir.join("pytest.ini").write(
|
2018-08-24 00:06:17 +08:00
|
|
|
textwrap.dedent(
|
|
|
|
"""\
|
|
|
|
[pytest]
|
|
|
|
addopts = --verbose
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
)
|
2011-11-08 02:08:41 +08:00
|
|
|
config = testdir.parseconfig(tmpdir)
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.option.color == "no"
|
|
|
|
assert config.option.reportchars == "s"
|
|
|
|
assert config.option.tbstyle == "short"
|
2010-10-28 01:35:27 +08:00
|
|
|
assert config.option.verbose
|
|
|
|
|
|
|
|
def test_tox_ini_wrong_version(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makefile(
|
|
|
|
".ini",
|
|
|
|
tox="""
|
2010-10-28 01:35:27 +08:00
|
|
|
[pytest]
|
|
|
|
minversion=9.0
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2015-04-28 18:05:08 +08:00
|
|
|
result = testdir.runpytest()
|
2010-10-28 01:35:27 +08:00
|
|
|
assert result.ret != 0
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stderr.fnmatch_lines(["*tox.ini:2*requires*9.0*actual*"])
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"section, name",
|
|
|
|
[("tool:pytest", "setup.cfg"), ("pytest", "tox.ini"), ("pytest", "pytest.ini")],
|
2016-08-17 08:30:07 +08:00
|
|
|
)
|
|
|
|
def test_ini_names(self, testdir, name, section):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.tmpdir.join(name).write(
|
|
|
|
textwrap.dedent(
|
|
|
|
"""
|
2016-08-17 08:30:07 +08:00
|
|
|
[{section}]
|
2010-11-07 23:10:22 +08:00
|
|
|
minversion = 1.0
|
2018-05-23 22:48:46 +08:00
|
|
|
""".format(
|
|
|
|
section=section
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2011-11-08 02:08:41 +08:00
|
|
|
config = testdir.parseconfig()
|
2010-11-07 23:10:22 +08:00
|
|
|
assert config.getini("minversion") == "1.0"
|
|
|
|
|
|
|
|
def test_toxini_before_lower_pytestini(self, testdir):
|
|
|
|
sub = testdir.tmpdir.mkdir("sub")
|
2018-05-23 22:48:46 +08:00
|
|
|
sub.join("tox.ini").write(
|
|
|
|
textwrap.dedent(
|
|
|
|
"""
|
2010-11-07 23:10:22 +08:00
|
|
|
[pytest]
|
|
|
|
minversion = 2.0
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
)
|
|
|
|
testdir.tmpdir.join("pytest.ini").write(
|
|
|
|
textwrap.dedent(
|
|
|
|
"""
|
2010-11-07 23:10:22 +08:00
|
|
|
[pytest]
|
|
|
|
minversion = 1.5
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
)
|
2011-11-08 02:08:41 +08:00
|
|
|
config = testdir.parseconfigure(sub)
|
2010-11-07 23:10:22 +08:00
|
|
|
assert config.getini("minversion") == "2.0"
|
|
|
|
|
2010-11-18 05:12:16 +08:00
|
|
|
@pytest.mark.xfail(reason="probably not needed")
|
2010-11-07 08:10:15 +08:00
|
|
|
def test_confcutdir(self, testdir):
|
|
|
|
sub = testdir.mkdir("sub")
|
|
|
|
sub.chdir()
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2010-11-07 08:10:15 +08:00
|
|
|
[pytest]
|
|
|
|
addopts = --qwe
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-28 17:54:45 +08:00
|
|
|
result = testdir.inline_run("--confcutdir=.")
|
2010-11-07 08:10:15 +08:00
|
|
|
assert result.ret == 0
|
2016-12-01 20:20:42 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestConfigCmdlineParsing(object):
|
2009-12-30 01:02:54 +08:00
|
|
|
def test_parsing_again_fails(self, testdir):
|
2011-11-08 02:08:41 +08:00
|
|
|
config = testdir.parseconfig()
|
2013-10-12 21:39:22 +08:00
|
|
|
pytest.raises(AssertionError, lambda: config.parse([]))
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2014-06-27 23:42:37 +08:00
|
|
|
def test_explicitly_specified_config_file_is_loaded(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2014-06-27 23:42:37 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("custom", "")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2014-06-27 23:42:37 +08:00
|
|
|
[pytest]
|
|
|
|
custom = 0
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makefile(
|
2018-09-02 08:58:48 +08:00
|
|
|
".ini",
|
2018-05-23 22:48:46 +08:00
|
|
|
custom="""
|
2014-06-27 23:42:37 +08:00
|
|
|
[pytest]
|
|
|
|
custom = 1
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2018-09-02 08:58:48 +08:00
|
|
|
config = testdir.parseconfig("-c", "custom.ini")
|
2014-06-27 23:42:37 +08:00
|
|
|
assert config.getini("custom") == "1"
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makefile(
|
|
|
|
".cfg",
|
|
|
|
custom_tool_pytest_section="""
|
2018-02-28 00:16:45 +08:00
|
|
|
[tool:pytest]
|
|
|
|
custom = 1
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2018-02-28 00:16:45 +08:00
|
|
|
config = testdir.parseconfig("-c", "custom_tool_pytest_section.cfg")
|
|
|
|
assert config.getini("custom") == "1"
|
|
|
|
|
2016-04-20 01:27:37 +08:00
|
|
|
def test_absolute_win32_path(self, testdir):
|
2018-09-02 08:58:48 +08:00
|
|
|
temp_ini_file = testdir.makefile(
|
|
|
|
".ini",
|
2018-05-23 22:48:46 +08:00
|
|
|
custom="""
|
2016-04-20 01:27:37 +08:00
|
|
|
[pytest]
|
|
|
|
addopts = --version
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2016-04-20 01:27:37 +08:00
|
|
|
from os.path import normpath
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2018-09-02 08:58:48 +08:00
|
|
|
temp_ini_file = normpath(str(temp_ini_file))
|
|
|
|
ret = pytest.main(["-c", temp_ini_file])
|
2016-04-20 01:27:37 +08:00
|
|
|
assert ret == _pytest.main.EXIT_OK
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestConfigAPI(object):
|
2010-11-06 06:37:31 +08:00
|
|
|
def test_config_trace(self, testdir):
|
2013-09-29 04:22:53 +08:00
|
|
|
config = testdir.parseconfig()
|
2017-11-04 23:17:20 +08:00
|
|
|
values = []
|
|
|
|
config.trace.root.setwriter(values.append)
|
2010-11-06 06:37:31 +08:00
|
|
|
config.trace("hello")
|
2017-11-04 23:17:20 +08:00
|
|
|
assert len(values) == 1
|
|
|
|
assert values[0] == "hello [config]\n"
|
2010-11-06 06:37:31 +08:00
|
|
|
|
2012-11-06 21:09:12 +08:00
|
|
|
def test_config_getoption(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2012-11-06 21:09:12 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption("--hello", "-X", dest="hello")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2012-11-06 21:09:12 +08:00
|
|
|
config = testdir.parseconfig("--hello=this")
|
|
|
|
for x in ("hello", "--hello", "-X"):
|
|
|
|
assert config.getoption(x) == "this"
|
|
|
|
pytest.raises(ValueError, "config.getoption('qweqwe')")
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.skipif("sys.version_info[0] < 3")
|
2013-10-01 20:20:20 +08:00
|
|
|
def test_config_getoption_unicode(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2013-10-01 20:20:20 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
2017-03-21 09:01:22 +08:00
|
|
|
parser.addoption('--hello', type=str)
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
config = testdir.parseconfig("--hello=this")
|
|
|
|
assert config.getoption("hello") == "this"
|
2013-10-01 20:20:20 +08:00
|
|
|
|
2009-03-02 19:14:59 +08:00
|
|
|
def test_config_getvalueorskip(self, testdir):
|
|
|
|
config = testdir.parseconfig()
|
2018-05-23 22:48:46 +08:00
|
|
|
pytest.raises(pytest.skip.Exception, "config.getvalueorskip('hello')")
|
2009-03-02 19:14:59 +08:00
|
|
|
verbose = config.getvalueorskip("verbose")
|
|
|
|
assert verbose == config.option.verbose
|
2014-04-03 04:30:45 +08:00
|
|
|
|
2014-05-14 13:36:31 +08:00
|
|
|
def test_config_getvalueorskip_None(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2014-05-14 13:36:31 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption("--hello")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2014-05-14 13:36:31 +08:00
|
|
|
config = testdir.parseconfig()
|
2014-06-16 17:27:32 +08:00
|
|
|
with pytest.raises(pytest.skip.Exception):
|
2018-05-23 22:48:46 +08:00
|
|
|
config.getvalueorskip("hello")
|
2014-05-14 13:36:31 +08:00
|
|
|
|
2014-04-03 04:30:45 +08:00
|
|
|
def test_getoption(self, testdir):
|
|
|
|
config = testdir.parseconfig()
|
|
|
|
with pytest.raises(ValueError):
|
2018-05-23 22:48:46 +08:00
|
|
|
config.getvalue("x")
|
2014-04-03 04:30:45 +08:00
|
|
|
assert config.getoption("x", 1) == 1
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-12-30 01:02:54 +08:00
|
|
|
def test_getconftest_pathlist(self, testdir, tmpdir):
|
2009-02-27 18:18:27 +08:00
|
|
|
somepath = tmpdir.join("x", "y", "z")
|
|
|
|
p = tmpdir.join("conftest.py")
|
|
|
|
p.write("pathlist = ['.', %r]" % str(somepath))
|
2011-11-08 02:08:41 +08:00
|
|
|
config = testdir.parseconfigure(p)
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config._getconftest_pathlist("notexist", path=tmpdir) is None
|
|
|
|
pl = config._getconftest_pathlist("pathlist", path=tmpdir)
|
2009-08-30 02:04:48 +08:00
|
|
|
print(pl)
|
2009-02-27 18:18:27 +08:00
|
|
|
assert len(pl) == 2
|
|
|
|
assert pl[0] == tmpdir
|
|
|
|
assert pl[1] == somepath
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2010-11-01 00:41:58 +08:00
|
|
|
def test_addini(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-11-01 00:41:58 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("myname", "my new ini value")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2010-11-01 00:41:58 +08:00
|
|
|
[pytest]
|
|
|
|
myname=hello
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2010-11-01 00:41:58 +08:00
|
|
|
config = testdir.parseconfig()
|
|
|
|
val = config.getini("myname")
|
|
|
|
assert val == "hello"
|
2018-05-23 22:48:46 +08:00
|
|
|
pytest.raises(ValueError, config.getini, "other")
|
2010-11-01 00:41:58 +08:00
|
|
|
|
|
|
|
def test_addini_pathlist(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-11-01 00:41:58 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("paths", "my new ini value", type="pathlist")
|
|
|
|
parser.addini("abc", "abc value")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
p = testdir.makeini(
|
|
|
|
"""
|
2010-11-01 00:41:58 +08:00
|
|
|
[pytest]
|
|
|
|
paths=hello world/sub.py
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2010-11-01 00:41:58 +08:00
|
|
|
config = testdir.parseconfig()
|
2017-11-04 23:17:20 +08:00
|
|
|
values = config.getini("paths")
|
|
|
|
assert len(values) == 2
|
2018-05-23 22:48:46 +08:00
|
|
|
assert values[0] == p.dirpath("hello")
|
|
|
|
assert values[1] == p.dirpath("world/sub.py")
|
|
|
|
pytest.raises(ValueError, config.getini, "other")
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2010-11-05 06:21:26 +08:00
|
|
|
def test_addini_args(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-11-05 06:21:26 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("args", "new args", type="args")
|
|
|
|
parser.addini("a2", "", "args", default="1 2 3".split())
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2010-11-05 06:21:26 +08:00
|
|
|
[pytest]
|
|
|
|
args=123 "123 hello" "this"
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2010-11-05 06:21:26 +08:00
|
|
|
config = testdir.parseconfig()
|
2017-11-04 23:17:20 +08:00
|
|
|
values = config.getini("args")
|
|
|
|
assert len(values) == 3
|
|
|
|
assert values == ["123", "123 hello", "this"]
|
|
|
|
values = config.getini("a2")
|
|
|
|
assert values == list("123")
|
2010-11-05 06:21:26 +08:00
|
|
|
|
2010-11-06 06:37:31 +08:00
|
|
|
def test_addini_linelist(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-11-06 06:37:31 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("xy", "", type="linelist")
|
|
|
|
parser.addini("a2", "", "linelist")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2010-11-06 06:37:31 +08:00
|
|
|
[pytest]
|
|
|
|
xy= 123 345
|
|
|
|
second line
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2010-11-06 06:37:31 +08:00
|
|
|
config = testdir.parseconfig()
|
2017-11-04 23:17:20 +08:00
|
|
|
values = config.getini("xy")
|
|
|
|
assert len(values) == 2
|
|
|
|
assert values == ["123 345", "second line"]
|
|
|
|
values = config.getini("a2")
|
|
|
|
assert values == []
|
2010-11-06 06:37:31 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"str_val, bool_val", [("True", True), ("no", False), ("no-ini", True)]
|
|
|
|
)
|
2016-02-15 05:27:48 +08:00
|
|
|
def test_addini_bool(self, testdir, str_val, bool_val):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2016-02-15 05:27:48 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("strip", "", type="bool", default=True)
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
if str_val != "no-ini":
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2016-02-15 05:27:48 +08:00
|
|
|
[pytest]
|
|
|
|
strip=%s
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
% str_val
|
|
|
|
)
|
2016-02-15 05:27:48 +08:00
|
|
|
config = testdir.parseconfig()
|
|
|
|
assert config.getini("strip") is bool_val
|
|
|
|
|
2011-11-12 06:56:08 +08:00
|
|
|
def test_addinivalue_line_existing(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2011-11-12 06:56:08 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("xy", "", type="linelist")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2011-11-12 06:56:08 +08:00
|
|
|
[pytest]
|
|
|
|
xy= 123
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2011-11-12 06:56:08 +08:00
|
|
|
config = testdir.parseconfig()
|
2017-11-04 23:17:20 +08:00
|
|
|
values = config.getini("xy")
|
|
|
|
assert len(values) == 1
|
|
|
|
assert values == ["123"]
|
2011-11-12 06:56:08 +08:00
|
|
|
config.addinivalue_line("xy", "456")
|
2017-11-04 23:17:20 +08:00
|
|
|
values = config.getini("xy")
|
|
|
|
assert len(values) == 2
|
|
|
|
assert values == ["123", "456"]
|
2011-11-12 06:56:08 +08:00
|
|
|
|
|
|
|
def test_addinivalue_line_new(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2011-11-12 06:56:08 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini("xy", "", type="linelist")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2011-11-12 06:56:08 +08:00
|
|
|
config = testdir.parseconfig()
|
|
|
|
assert not config.getini("xy")
|
|
|
|
config.addinivalue_line("xy", "456")
|
2017-11-04 23:17:20 +08:00
|
|
|
values = config.getini("xy")
|
|
|
|
assert len(values) == 1
|
|
|
|
assert values == ["456"]
|
2011-11-12 06:56:08 +08:00
|
|
|
config.addinivalue_line("xy", "123")
|
2017-11-04 23:17:20 +08:00
|
|
|
values = config.getini("xy")
|
|
|
|
assert len(values) == 2
|
|
|
|
assert values == ["456", "123"]
|
2011-11-12 06:56:08 +08:00
|
|
|
|
2016-11-23 19:47:36 +08:00
|
|
|
def test_confcutdir_check_isdir(self, testdir):
|
|
|
|
"""Give an error if --confcutdir is not a valid directory (#2078)"""
|
|
|
|
with pytest.raises(pytest.UsageError):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.parseconfig(
|
|
|
|
"--confcutdir", testdir.tmpdir.join("file").ensure(file=1)
|
|
|
|
)
|
2016-11-23 19:47:36 +08:00
|
|
|
with pytest.raises(pytest.UsageError):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.parseconfig("--confcutdir", testdir.tmpdir.join("inexistant"))
|
|
|
|
config = testdir.parseconfig(
|
|
|
|
"--confcutdir", testdir.tmpdir.join("dir").ensure(dir=1)
|
|
|
|
)
|
|
|
|
assert config.getoption("confcutdir") == str(testdir.tmpdir.join("dir"))
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"names, expected",
|
|
|
|
[
|
|
|
|
(["bar.py"], ["bar"]),
|
|
|
|
(["foo", "bar.py"], []),
|
|
|
|
(["foo", "bar.pyc"], []),
|
|
|
|
(["foo", "__init__.py"], ["foo"]),
|
|
|
|
(["foo", "bar", "__init__.py"], []),
|
|
|
|
],
|
|
|
|
)
|
2017-07-29 03:03:07 +08:00
|
|
|
def test_iter_rewritable_modules(self, names, expected):
|
2018-05-23 22:48:46 +08:00
|
|
|
assert list(_iter_rewritable_modules(["/".join(names)])) == expected
|
2017-07-29 03:03:07 +08:00
|
|
|
|
2015-09-25 05:13:36 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestConfigFromdictargs(object):
|
2015-09-25 05:13:36 +08:00
|
|
|
def test_basic_behavior(self):
|
|
|
|
from _pytest.config import Config
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
option_dict = {"verbose": 444, "foo": "bar", "capture": "no"}
|
|
|
|
args = ["a", "b"]
|
2015-09-25 05:13:36 +08:00
|
|
|
|
|
|
|
config = Config.fromdictargs(option_dict, args)
|
|
|
|
with pytest.raises(AssertionError):
|
2018-05-23 22:48:46 +08:00
|
|
|
config.parse(["should refuse to parse again"])
|
2015-09-25 08:52:53 +08:00
|
|
|
assert config.option.verbose == 444
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.option.foo == "bar"
|
|
|
|
assert config.option.capture == "no"
|
2015-09-25 05:13:36 +08:00
|
|
|
assert config.args == args
|
|
|
|
|
|
|
|
def test_origargs(self):
|
|
|
|
"""Show that fromdictargs can handle args in their "orig" format"""
|
|
|
|
from _pytest.config import Config
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-09-25 05:13:36 +08:00
|
|
|
option_dict = {}
|
2018-05-23 22:48:46 +08:00
|
|
|
args = ["-vvvv", "-s", "a", "b"]
|
2015-09-25 05:13:36 +08:00
|
|
|
|
|
|
|
config = Config.fromdictargs(option_dict, args)
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.args == ["a", "b"]
|
2015-09-25 08:52:53 +08:00
|
|
|
assert config._origargs == args
|
2015-09-25 05:13:36 +08:00
|
|
|
assert config.option.verbose == 4
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.option.capture == "no"
|
2015-09-25 08:52:53 +08:00
|
|
|
|
|
|
|
def test_inifilename(self, tmpdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
tmpdir.join("foo/bar.ini").ensure().write(
|
2018-08-24 00:06:17 +08:00
|
|
|
textwrap.dedent(
|
|
|
|
"""\
|
|
|
|
[pytest]
|
|
|
|
name = value
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
)
|
2015-09-25 05:13:36 +08:00
|
|
|
|
|
|
|
from _pytest.config import Config
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
inifile = "../../foo/bar.ini"
|
|
|
|
option_dict = {"inifilename": inifile, "capture": "no"}
|
|
|
|
|
|
|
|
cwd = tmpdir.join("a/b")
|
|
|
|
cwd.join("pytest.ini").ensure().write(
|
2018-08-24 00:06:17 +08:00
|
|
|
textwrap.dedent(
|
|
|
|
"""\
|
|
|
|
[pytest]
|
|
|
|
name = wrong-value
|
|
|
|
should_not_be_set = true
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
)
|
2015-09-25 08:52:53 +08:00
|
|
|
with cwd.ensure(dir=True).as_cwd():
|
|
|
|
config = Config.fromdictargs(option_dict, ())
|
|
|
|
|
|
|
|
assert config.args == [str(cwd)]
|
2015-09-25 05:13:36 +08:00
|
|
|
assert config.option.inifilename == inifile
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.option.capture == "no"
|
2015-09-25 05:13:36 +08:00
|
|
|
|
|
|
|
# this indicates this is the file used for getting configuration values
|
|
|
|
assert config.inifile == inifile
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.inicfg.get("name") == "value"
|
|
|
|
assert config.inicfg.get("should_not_be_set") is None
|
2015-09-25 05:13:36 +08:00
|
|
|
|
|
|
|
|
2009-02-28 05:32:49 +08:00
|
|
|
def test_options_on_small_file_do_not_blow_up(testdir):
|
|
|
|
def runfiletest(opts):
|
2009-05-21 20:33:09 +08:00
|
|
|
reprec = testdir.inline_run(*opts)
|
|
|
|
passed, skipped, failed = reprec.countoutcomes()
|
2010-07-27 03:15:15 +08:00
|
|
|
assert failed == 2
|
2009-02-28 05:32:49 +08:00
|
|
|
assert skipped == passed == 0
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
path = testdir.makepyfile(
|
|
|
|
"""
|
2009-02-28 05:32:49 +08:00
|
|
|
def test_f1(): assert 0
|
|
|
|
def test_f2(): assert 0
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2009-02-28 05:32:49 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
for opts in (
|
|
|
|
[],
|
|
|
|
["-l"],
|
|
|
|
["-s"],
|
|
|
|
["--tb=no"],
|
|
|
|
["--tb=short"],
|
|
|
|
["--tb=long"],
|
|
|
|
["--fulltrace"],
|
|
|
|
["--traceconfig"],
|
|
|
|
["-v"],
|
|
|
|
["-v", "-v"],
|
|
|
|
):
|
2009-02-28 05:32:49 +08:00
|
|
|
runfiletest(opts + [path])
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2010-12-06 23:54:42 +08:00
|
|
|
def test_preparse_ordering_with_setuptools(testdir, monkeypatch):
|
2014-01-18 19:31:33 +08:00
|
|
|
pkg_resources = pytest.importorskip("pkg_resources")
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2010-01-03 00:17:13 +08:00
|
|
|
def my_iter(name):
|
|
|
|
assert name == "pytest11"
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class Dist(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
project_name = "spam"
|
|
|
|
version = "1.0"
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2016-06-22 18:42:11 +08:00
|
|
|
def _get_metadata(self, name):
|
2018-05-23 22:48:46 +08:00
|
|
|
return ["foo.txt,sha256=abc,123"]
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class EntryPoint(object):
|
2010-01-03 00:17:13 +08:00
|
|
|
name = "mytestplugin"
|
2016-06-22 18:42:11 +08:00
|
|
|
dist = Dist()
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2010-01-03 00:17:13 +08:00
|
|
|
def load(self):
|
2017-02-17 02:41:51 +08:00
|
|
|
class PseudoPlugin(object):
|
2010-01-03 00:17:13 +08:00
|
|
|
x = 42
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2010-01-03 00:17:13 +08:00
|
|
|
return PseudoPlugin()
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2010-01-03 00:17:13 +08:00
|
|
|
return iter([EntryPoint()])
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
monkeypatch.setattr(pkg_resources, "iter_entry_points", my_iter)
|
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-01-03 00:17:13 +08:00
|
|
|
pytest_plugins = "mytestplugin",
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2010-01-03 00:17:13 +08:00
|
|
|
monkeypatch.setenv("PYTEST_PLUGINS", "mytestplugin")
|
|
|
|
config = testdir.parseconfig()
|
|
|
|
plugin = config.pluginmanager.getplugin("mytestplugin")
|
|
|
|
assert plugin.x == 42
|
2010-11-01 00:41:58 +08:00
|
|
|
|
2016-05-23 14:13:41 +08:00
|
|
|
|
|
|
|
def test_setuptools_importerror_issue1479(testdir, monkeypatch):
|
|
|
|
pkg_resources = pytest.importorskip("pkg_resources")
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2016-05-23 14:13:41 +08:00
|
|
|
def my_iter(name):
|
|
|
|
assert name == "pytest11"
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class Dist(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
project_name = "spam"
|
|
|
|
version = "1.0"
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2016-07-14 19:42:29 +08:00
|
|
|
def _get_metadata(self, name):
|
2018-05-23 22:48:46 +08:00
|
|
|
return ["foo.txt,sha256=abc,123"]
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class EntryPoint(object):
|
2016-05-23 14:13:41 +08:00
|
|
|
name = "mytestplugin"
|
2016-07-14 19:42:29 +08:00
|
|
|
dist = Dist()
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2016-05-23 14:13:41 +08:00
|
|
|
def load(self):
|
|
|
|
raise ImportError("Don't hide me!")
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2016-05-23 14:13:41 +08:00
|
|
|
return iter([EntryPoint()])
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
monkeypatch.setattr(pkg_resources, "iter_entry_points", my_iter)
|
2016-05-23 14:13:41 +08:00
|
|
|
with pytest.raises(ImportError):
|
|
|
|
testdir.parseconfig()
|
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize("block_it", [True, False])
|
2017-11-29 07:29:58 +08:00
|
|
|
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch, block_it):
|
2014-01-18 19:31:33 +08:00
|
|
|
pkg_resources = pytest.importorskip("pkg_resources")
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-11-29 07:29:58 +08:00
|
|
|
plugin_module_placeholder = object()
|
|
|
|
|
2010-12-06 23:54:42 +08:00
|
|
|
def my_iter(name):
|
|
|
|
assert name == "pytest11"
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class Dist(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
project_name = "spam"
|
|
|
|
version = "1.0"
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2016-06-22 18:42:11 +08:00
|
|
|
def _get_metadata(self, name):
|
2018-05-23 22:48:46 +08:00
|
|
|
return ["foo.txt,sha256=abc,123"]
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class EntryPoint(object):
|
2010-12-06 23:54:42 +08:00
|
|
|
name = "mytestplugin"
|
2016-06-22 18:42:11 +08:00
|
|
|
dist = Dist()
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2010-12-06 23:54:42 +08:00
|
|
|
def load(self):
|
2017-11-29 07:29:58 +08:00
|
|
|
return plugin_module_placeholder
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2010-12-06 23:54:42 +08:00
|
|
|
return iter([EntryPoint()])
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
monkeypatch.setattr(pkg_resources, "iter_entry_points", my_iter)
|
2017-11-29 07:29:58 +08:00
|
|
|
args = ("-p", "no:mytestplugin") if block_it else ()
|
|
|
|
config = testdir.parseconfig(*args)
|
2017-11-29 00:29:52 +08:00
|
|
|
config.pluginmanager.import_plugin("mytestplugin")
|
2017-11-29 07:29:58 +08:00
|
|
|
if block_it:
|
|
|
|
assert "mytestplugin" not in sys.modules
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.pluginmanager.get_plugin("mytestplugin") is None
|
2017-11-29 07:29:58 +08:00
|
|
|
else:
|
2018-06-26 21:35:27 +08:00
|
|
|
assert (
|
|
|
|
config.pluginmanager.get_plugin("mytestplugin") is plugin_module_placeholder
|
|
|
|
)
|
2010-12-07 19:14:12 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2018-08-07 04:17:24 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"parse_args,should_load", [(("-p", "mytestplugin"), True), ((), False)]
|
|
|
|
)
|
|
|
|
def test_disable_plugin_autoload(testdir, monkeypatch, parse_args, should_load):
|
|
|
|
pkg_resources = pytest.importorskip("pkg_resources")
|
|
|
|
|
|
|
|
def my_iter(name):
|
|
|
|
raise AssertionError("Should not be called")
|
|
|
|
|
|
|
|
class PseudoPlugin(object):
|
|
|
|
x = 42
|
|
|
|
|
|
|
|
monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
|
|
|
|
monkeypatch.setattr(pkg_resources, "iter_entry_points", my_iter)
|
|
|
|
monkeypatch.setitem(sys.modules, "mytestplugin", PseudoPlugin())
|
|
|
|
config = testdir.parseconfig(*parse_args)
|
|
|
|
has_loaded = config.pluginmanager.get_plugin("mytestplugin") is not None
|
|
|
|
assert has_loaded == should_load
|
|
|
|
|
|
|
|
|
2010-12-07 19:14:12 +08:00
|
|
|
def test_cmdline_processargs_simple(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-12-07 19:34:18 +08:00
|
|
|
def pytest_cmdline_preparse(args):
|
2010-12-07 19:14:12 +08:00
|
|
|
args.append("-h")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-28 18:05:08 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(["*pytest*", "*-h*"])
|
2012-11-06 21:09:12 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-07-09 08:22:08 +08:00
|
|
|
def test_invalid_options_show_extra_information(testdir):
|
|
|
|
"""display extra information when pytest exits due to unrecognized
|
|
|
|
options in the command-line"""
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2015-07-09 08:22:08 +08:00
|
|
|
[pytest]
|
|
|
|
addopts = --invalid-option
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-07-09 08:22:08 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stderr.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*error: unrecognized arguments: --invalid-option*",
|
|
|
|
"* inifile: %s*" % testdir.tmpdir.join("tox.ini"),
|
|
|
|
"* rootdir: %s*" % testdir.tmpdir,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"args",
|
|
|
|
[
|
|
|
|
["dir1", "dir2", "-v"],
|
|
|
|
["dir1", "-v", "dir2"],
|
|
|
|
["dir2", "-v", "dir1"],
|
|
|
|
["-v", "dir2", "dir1"],
|
|
|
|
],
|
|
|
|
)
|
2015-08-26 09:08:05 +08:00
|
|
|
def test_consider_args_after_options_for_rootdir_and_inifile(testdir, args):
|
|
|
|
"""
|
|
|
|
Consider all arguments in the command-line for rootdir and inifile
|
|
|
|
discovery, even if they happen to occur after an option. #949
|
|
|
|
"""
|
|
|
|
# replace "dir1" and "dir2" from "args" into their real directory
|
2018-05-23 22:48:46 +08:00
|
|
|
root = testdir.tmpdir.mkdir("myroot")
|
|
|
|
d1 = root.mkdir("dir1")
|
|
|
|
d2 = root.mkdir("dir2")
|
2015-08-26 09:08:05 +08:00
|
|
|
for i, arg in enumerate(args):
|
2018-05-23 22:48:46 +08:00
|
|
|
if arg == "dir1":
|
2015-08-26 09:08:05 +08:00
|
|
|
args[i] = d1
|
2018-05-23 22:48:46 +08:00
|
|
|
elif arg == "dir2":
|
2015-08-26 09:08:05 +08:00
|
|
|
args[i] = d2
|
2016-06-21 00:47:12 +08:00
|
|
|
with root.as_cwd():
|
|
|
|
result = testdir.runpytest(*args)
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(["*rootdir: *myroot, inifile:"])
|
2015-08-26 09:08:05 +08:00
|
|
|
|
|
|
|
|
2012-11-20 18:52:06 +08:00
|
|
|
@pytest.mark.skipif("sys.platform == 'win32'")
|
2012-11-12 17:15:43 +08:00
|
|
|
def test_toolongargs_issue224(testdir):
|
|
|
|
result = testdir.runpytest("-m", "hello" * 500)
|
2015-07-05 01:42:22 +08:00
|
|
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
2013-09-30 19:14:14 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2016-12-20 18:22:18 +08:00
|
|
|
def test_config_in_subdirectory_colon_command_line_issue2148(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
conftest_source = """
|
2016-12-20 18:22:18 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini('foo', 'foo')
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2016-12-20 18:22:18 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makefile(
|
|
|
|
".ini",
|
|
|
|
**{"pytest": "[pytest]\nfoo = root", "subdir/pytest": "[pytest]\nfoo = subdir"}
|
|
|
|
)
|
2016-12-20 18:22:18 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
**{
|
|
|
|
"conftest": conftest_source,
|
|
|
|
"subdir/conftest": conftest_source,
|
|
|
|
"subdir/test_foo": """
|
2016-12-20 18:22:18 +08:00
|
|
|
def test_foo(pytestconfig):
|
|
|
|
assert pytestconfig.getini('foo') == 'subdir'
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
}
|
|
|
|
)
|
2016-12-20 18:22:18 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
result = testdir.runpytest("subdir/test_foo.py::test_foo")
|
2016-12-20 18:22:18 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
|
2013-09-30 19:14:14 +08:00
|
|
|
def test_notify_exception(testdir, capfd):
|
|
|
|
config = testdir.parseconfig()
|
|
|
|
excinfo = pytest.raises(ValueError, "raise ValueError(1)")
|
|
|
|
config.notify_exception(excinfo)
|
|
|
|
out, err = capfd.readouterr()
|
|
|
|
assert "ValueError" in err
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class A(object):
|
2013-09-30 19:14:14 +08:00
|
|
|
def pytest_internalerror(self, excrepr):
|
|
|
|
return True
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2013-09-30 19:14:14 +08:00
|
|
|
config.pluginmanager.register(A())
|
|
|
|
config.notify_exception(excinfo)
|
|
|
|
out, err = capfd.readouterr()
|
|
|
|
assert not err
|
|
|
|
|
2013-09-30 19:14:16 +08:00
|
|
|
|
|
|
|
def test_load_initial_conftest_last_ordering(testdir):
|
2017-07-17 07:25:09 +08:00
|
|
|
from _pytest.config import get_config
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-04-26 00:14:41 +08:00
|
|
|
pm = get_config().pluginmanager
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class My(object):
|
2013-09-30 19:14:16 +08:00
|
|
|
def pytest_load_initial_conftests(self):
|
|
|
|
pass
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2013-09-30 19:14:16 +08:00
|
|
|
m = My()
|
|
|
|
pm.register(m)
|
2015-04-25 17:29:11 +08:00
|
|
|
hc = pm.hook.pytest_load_initial_conftests
|
2017-11-04 23:17:20 +08:00
|
|
|
values = hc._nonwrappers + hc._wrappers
|
2018-05-23 22:48:46 +08:00
|
|
|
expected = ["_pytest.config", "test_config", "_pytest.capture"]
|
2017-11-04 23:17:20 +08:00
|
|
|
assert [x.function.__module__ for x in values] == expected
|
2016-06-20 20:45:13 +08:00
|
|
|
|
2013-09-30 19:14:16 +08:00
|
|
|
|
2017-01-13 00:23:09 +08:00
|
|
|
def test_get_plugin_specs_as_list():
|
|
|
|
from _pytest.config import _get_plugin_specs_as_list
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2017-01-13 00:23:09 +08:00
|
|
|
with pytest.raises(pytest.UsageError):
|
2018-05-23 22:48:46 +08:00
|
|
|
_get_plugin_specs_as_list({"foo"})
|
2017-01-13 00:23:09 +08:00
|
|
|
with pytest.raises(pytest.UsageError):
|
|
|
|
_get_plugin_specs_as_list(dict())
|
|
|
|
|
|
|
|
assert _get_plugin_specs_as_list(None) == []
|
2018-05-23 22:48:46 +08:00
|
|
|
assert _get_plugin_specs_as_list("") == []
|
|
|
|
assert _get_plugin_specs_as_list("foo") == ["foo"]
|
|
|
|
assert _get_plugin_specs_as_list("foo,bar") == ["foo", "bar"]
|
|
|
|
assert _get_plugin_specs_as_list(["foo", "bar"]) == ["foo", "bar"]
|
|
|
|
assert _get_plugin_specs_as_list(("foo", "bar")) == ["foo", "bar"]
|
2017-01-13 00:23:09 +08:00
|
|
|
|
|
|
|
|
2018-08-05 03:35:24 +08:00
|
|
|
def test_collect_pytest_prefix_bug_integration(testdir):
|
|
|
|
"""Integration test for issue #3775"""
|
|
|
|
p = testdir.copy_example("config/collect_pytest_prefix")
|
|
|
|
result = testdir.runpytest(p)
|
|
|
|
result.stdout.fnmatch_lines("* 1 passed *")
|
|
|
|
|
|
|
|
|
|
|
|
def test_collect_pytest_prefix_bug(pytestconfig):
|
|
|
|
"""Ensure we collect only actual functions from conftest files (#3775)"""
|
|
|
|
|
|
|
|
class Dummy(object):
|
|
|
|
class pytest_something(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
pm = pytestconfig.pluginmanager
|
|
|
|
assert pm.parse_hookimpl_opts(Dummy(), "pytest_something") is None
|
|
|
|
|
|
|
|
|
2018-09-02 08:58:48 +08:00
|
|
|
class TestLegacyWarning(object):
|
|
|
|
@pytest.mark.filterwarnings("default")
|
2014-03-12 05:10:17 +08:00
|
|
|
def test_warn_config(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2017-11-04 23:17:20 +08:00
|
|
|
values = []
|
2018-09-02 08:58:48 +08:00
|
|
|
def pytest_runtest_setup(item):
|
|
|
|
item.config.warn("C1", "hello")
|
2014-03-12 05:10:17 +08:00
|
|
|
def pytest_logwarning(code, message):
|
2015-04-27 21:06:47 +08:00
|
|
|
if message == "hello" and code == "C1":
|
2017-11-04 23:17:20 +08:00
|
|
|
values.append(1)
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2014-03-12 05:10:17 +08:00
|
|
|
def test_proper(pytestconfig):
|
|
|
|
import conftest
|
2017-11-04 23:17:20 +08:00
|
|
|
assert conftest.values == [1]
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-09-02 08:58:48 +08:00
|
|
|
result = testdir.runpytest()
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
["*hello", "*config.warn has been deprecated*", "*1 passed*"]
|
|
|
|
)
|
2013-09-30 19:14:16 +08:00
|
|
|
|
2018-09-02 08:58:48 +08:00
|
|
|
@pytest.mark.filterwarnings("default")
|
2018-09-05 03:48:21 +08:00
|
|
|
@pytest.mark.parametrize("use_kw", [True, False])
|
|
|
|
def test_warn_on_test_item_from_request(self, testdir, use_kw):
|
|
|
|
code_kw = "code=" if use_kw else ""
|
|
|
|
message_kw = "message=" if use_kw else ""
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2014-03-12 05:10:17 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def fix(request):
|
2018-09-05 03:48:21 +08:00
|
|
|
request.node.warn({code_kw}"T1", {message_kw}"hello")
|
2016-08-12 06:29:03 +08:00
|
|
|
|
2014-03-12 05:10:17 +08:00
|
|
|
def test_hello(fix):
|
|
|
|
pass
|
2018-09-05 03:48:21 +08:00
|
|
|
""".format(
|
|
|
|
code_kw=code_kw, message_kw=message_kw
|
|
|
|
)
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
2016-07-05 21:22:27 +08:00
|
|
|
result = testdir.runpytest("--disable-pytest-warnings")
|
|
|
|
assert "hello" not in result.stdout.str()
|
2015-04-27 21:06:47 +08:00
|
|
|
|
2016-07-05 21:22:27 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
"""
|
2017-03-08 07:47:43 +08:00
|
|
|
===*warnings summary*===
|
2017-03-17 08:55:03 +08:00
|
|
|
*test_warn_on_test_item_from_request.py::test_hello*
|
2017-03-08 07:47:43 +08:00
|
|
|
*hello*
|
2018-09-05 02:07:52 +08:00
|
|
|
*test_warn_on_test_item_from_request.py:7:*Node.warn(code, message) form has been deprecated*
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-02-27 04:56:44 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestRootdir(object):
|
2015-02-27 04:56:44 +08:00
|
|
|
def test_simple_noini(self, tmpdir):
|
|
|
|
assert get_common_ancestor([tmpdir]) == tmpdir
|
2016-06-21 00:47:12 +08:00
|
|
|
a = tmpdir.mkdir("a")
|
|
|
|
assert get_common_ancestor([a, tmpdir]) == tmpdir
|
|
|
|
assert get_common_ancestor([tmpdir, a]) == tmpdir
|
2015-02-27 04:56:44 +08:00
|
|
|
with tmpdir.as_cwd():
|
|
|
|
assert get_common_ancestor([]) == tmpdir
|
2018-05-23 22:48:46 +08:00
|
|
|
no_path = tmpdir.join("does-not-exist")
|
2016-06-21 00:47:12 +08:00
|
|
|
assert get_common_ancestor([no_path]) == tmpdir
|
2018-05-23 22:48:46 +08:00
|
|
|
assert get_common_ancestor([no_path.join("a")]) == tmpdir
|
2015-02-27 04:56:44 +08:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
|
|
|
|
def test_with_ini(self, tmpdir, name):
|
|
|
|
inifile = tmpdir.join(name)
|
2018-09-02 08:58:48 +08:00
|
|
|
inifile.write("[pytest]\n" if name != "setup.cfg" else "[tool:pytest]\n")
|
2015-02-27 04:56:44 +08:00
|
|
|
|
|
|
|
a = tmpdir.mkdir("a")
|
|
|
|
b = a.mkdir("b")
|
|
|
|
for args in ([tmpdir], [a], [b]):
|
|
|
|
rootdir, inifile, inicfg = determine_setup(None, args)
|
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile == inifile
|
2017-07-17 07:25:08 +08:00
|
|
|
rootdir, inifile, inicfg = determine_setup(None, [b, a])
|
2015-02-27 04:56:44 +08:00
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile == inifile
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("name", "setup.cfg tox.ini".split())
|
|
|
|
def test_pytestini_overides_empty_other(self, tmpdir, name):
|
|
|
|
inifile = tmpdir.ensure("pytest.ini")
|
|
|
|
a = tmpdir.mkdir("a")
|
|
|
|
a.ensure(name)
|
|
|
|
rootdir, inifile, inicfg = determine_setup(None, [a])
|
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile == inifile
|
|
|
|
|
|
|
|
def test_setuppy_fallback(self, tmpdir):
|
|
|
|
a = tmpdir.mkdir("a")
|
|
|
|
a.ensure("setup.cfg")
|
|
|
|
tmpdir.ensure("setup.py")
|
|
|
|
rootdir, inifile, inicfg = determine_setup(None, [a])
|
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile is None
|
|
|
|
assert inicfg == {}
|
|
|
|
|
2016-08-07 04:58:17 +08:00
|
|
|
def test_nothing(self, tmpdir, monkeypatch):
|
|
|
|
monkeypatch.chdir(str(tmpdir))
|
2015-02-27 04:56:44 +08:00
|
|
|
rootdir, inifile, inicfg = determine_setup(None, [tmpdir])
|
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile is None
|
|
|
|
assert inicfg == {}
|
|
|
|
|
|
|
|
def test_with_specific_inifile(self, tmpdir):
|
|
|
|
inifile = tmpdir.ensure("pytest.ini")
|
|
|
|
rootdir, inifile, inicfg = determine_setup(inifile, [tmpdir])
|
|
|
|
assert rootdir == tmpdir
|
2016-06-25 22:12:42 +08:00
|
|
|
|
2016-08-18 09:39:23 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestOverrideIniArgs(object):
|
2016-06-25 22:12:42 +08:00
|
|
|
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
|
|
|
|
def test_override_ini_names(self, testdir, name):
|
2018-09-02 08:58:48 +08:00
|
|
|
section = "[pytest]" if name != "setup.cfg" else "[tool:pytest]"
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.tmpdir.join(name).write(
|
|
|
|
textwrap.dedent(
|
|
|
|
"""
|
2018-09-02 08:58:48 +08:00
|
|
|
{section}
|
|
|
|
custom = 1.0""".format(
|
|
|
|
section=section
|
|
|
|
)
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2016-06-25 22:12:42 +08:00
|
|
|
def pytest_addoption(parser):
|
2018-05-23 22:48:46 +08:00
|
|
|
parser.addini("custom", "")"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2016-06-25 22:12:42 +08:00
|
|
|
def test_pass(pytestconfig):
|
|
|
|
ini_val = pytestconfig.getini("custom")
|
2018-05-23 22:48:46 +08:00
|
|
|
print('\\ncustom_option:%s\\n' % ini_val)"""
|
|
|
|
)
|
2016-06-25 22:12:42 +08:00
|
|
|
|
|
|
|
result = testdir.runpytest("--override-ini", "custom=2.0", "-s")
|
|
|
|
assert result.ret == 0
|
2016-07-24 00:09:42 +08:00
|
|
|
result.stdout.fnmatch_lines(["custom_option:2.0"])
|
2016-06-25 22:12:42 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
result = testdir.runpytest(
|
|
|
|
"--override-ini", "custom=2.0", "--override-ini=custom=3.0", "-s"
|
|
|
|
)
|
2016-06-25 22:12:42 +08:00
|
|
|
assert result.ret == 0
|
2016-07-24 00:09:42 +08:00
|
|
|
result.stdout.fnmatch_lines(["custom_option:3.0"])
|
2016-06-25 22:12:42 +08:00
|
|
|
|
|
|
|
def test_override_ini_pathlist(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2016-07-24 00:09:42 +08:00
|
|
|
def pytest_addoption(parser):
|
2018-05-23 22:48:46 +08:00
|
|
|
parser.addini("paths", "my new ini value", type="pathlist")"""
|
|
|
|
)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2016-07-24 00:09:42 +08:00
|
|
|
[pytest]
|
2018-05-23 22:48:46 +08:00
|
|
|
paths=blah.py"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2016-07-24 00:09:42 +08:00
|
|
|
import py.path
|
|
|
|
def test_pathlist(pytestconfig):
|
|
|
|
config_paths = pytestconfig.getini("paths")
|
|
|
|
print(config_paths)
|
|
|
|
for cpf in config_paths:
|
2018-05-23 22:48:46 +08:00
|
|
|
print('\\nuser_path:%s' % cpf.basename)"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest(
|
|
|
|
"--override-ini", "paths=foo/bar1.py foo/bar2.py", "-s"
|
|
|
|
)
|
|
|
|
result.stdout.fnmatch_lines(["user_path:bar1.py", "user_path:bar2.py"])
|
2016-06-25 22:12:42 +08:00
|
|
|
|
|
|
|
def test_override_multiple_and_default(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2016-07-24 00:09:42 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
addini = parser.addini
|
|
|
|
addini("custom_option_1", "", default="o1")
|
|
|
|
addini("custom_option_2", "", default="o2")
|
|
|
|
addini("custom_option_3", "", default=False, type="bool")
|
2018-05-23 22:48:46 +08:00
|
|
|
addini("custom_option_4", "", default=True, type="bool")"""
|
|
|
|
)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2016-07-24 00:09:42 +08:00
|
|
|
[pytest]
|
|
|
|
custom_option_1=custom_option_1
|
2018-01-24 07:13:20 +08:00
|
|
|
custom_option_2=custom_option_2
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2016-07-24 00:09:42 +08:00
|
|
|
def test_multiple_options(pytestconfig):
|
|
|
|
prefix = "custom_option"
|
|
|
|
for x in range(1, 5):
|
|
|
|
ini_value=pytestconfig.getini("%s_%d" % (prefix, x))
|
2018-01-24 07:13:20 +08:00
|
|
|
print('\\nini%d:%s' % (x, ini_value))
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2016-07-24 00:09:42 +08:00
|
|
|
result = testdir.runpytest(
|
2018-05-23 22:48:46 +08:00
|
|
|
"--override-ini",
|
|
|
|
"custom_option_1=fulldir=/tmp/user1",
|
|
|
|
"-o",
|
|
|
|
"custom_option_2=url=/tmp/user2?a=b&d=e",
|
|
|
|
"-o",
|
|
|
|
"custom_option_3=True",
|
|
|
|
"-o",
|
|
|
|
"custom_option_4=no",
|
|
|
|
"-s",
|
|
|
|
)
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"ini1:fulldir=/tmp/user1",
|
|
|
|
"ini2:url=/tmp/user2?a=b&d=e",
|
|
|
|
"ini3:True",
|
|
|
|
"ini4:False",
|
|
|
|
]
|
|
|
|
)
|
2016-08-07 04:58:17 +08:00
|
|
|
|
2016-12-01 20:20:42 +08:00
|
|
|
def test_override_ini_usage_error_bad_style(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2016-12-01 20:20:42 +08:00
|
|
|
[pytest]
|
|
|
|
xdist_strict=False
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("--override-ini", "xdist_strict True", "-s")
|
2016-12-01 20:20:42 +08:00
|
|
|
result.stderr.fnmatch_lines(["*ERROR* *expects option=value*"])
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize("with_ini", [True, False])
|
2017-02-09 08:39:34 +08:00
|
|
|
def test_override_ini_handled_asap(self, testdir, with_ini):
|
|
|
|
"""-o should be handled as soon as possible and always override what's in ini files (#2238)"""
|
|
|
|
if with_ini:
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2017-02-09 08:39:34 +08:00
|
|
|
[pytest]
|
|
|
|
python_files=test_*.py
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
unittest_ini_handle="""
|
2017-02-09 08:39:34 +08:00
|
|
|
def test():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("--override-ini", "python_files=unittest_*.py")
|
2017-02-09 08:39:34 +08:00
|
|
|
result.stdout.fnmatch_lines(["*1 passed in*"])
|
|
|
|
|
2016-08-07 04:58:17 +08:00
|
|
|
def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch):
|
|
|
|
monkeypatch.chdir(str(tmpdir))
|
2016-06-21 00:47:12 +08:00
|
|
|
a = tmpdir.mkdir("a")
|
|
|
|
b = tmpdir.mkdir("b")
|
|
|
|
rootdir, inifile, inicfg = determine_setup(None, [a, b])
|
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile is None
|
|
|
|
|
|
|
|
def test_with_arg_outside_cwd_with_inifile(self, tmpdir):
|
|
|
|
a = tmpdir.mkdir("a")
|
|
|
|
b = tmpdir.mkdir("b")
|
|
|
|
inifile = a.ensure("pytest.ini")
|
|
|
|
rootdir, parsed_inifile, inicfg = determine_setup(None, [a, b])
|
|
|
|
assert rootdir == a
|
|
|
|
assert inifile == parsed_inifile
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize("dirs", ([], ["does-not-exist"], ["a/does-not-exist"]))
|
2016-06-21 00:47:12 +08:00
|
|
|
def test_with_non_dir_arg(self, dirs, tmpdir):
|
|
|
|
with tmpdir.ensure(dir=True).as_cwd():
|
|
|
|
rootdir, inifile, inicfg = determine_setup(None, dirs)
|
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile is None
|
|
|
|
|
|
|
|
def test_with_existing_file_in_subdir(self, tmpdir):
|
|
|
|
a = tmpdir.mkdir("a")
|
|
|
|
a.ensure("exist")
|
|
|
|
with tmpdir.as_cwd():
|
2018-05-23 22:48:46 +08:00
|
|
|
rootdir, inifile, inicfg = determine_setup(None, ["a/exist"])
|
2016-06-21 00:47:12 +08:00
|
|
|
assert rootdir == tmpdir
|
|
|
|
assert inifile is None
|
2017-10-11 01:03:15 +08:00
|
|
|
|
2018-01-24 07:13:20 +08:00
|
|
|
def test_addopts_before_initini(self, monkeypatch):
|
2018-05-23 22:48:46 +08:00
|
|
|
cache_dir = ".custom_cache"
|
|
|
|
monkeypatch.setenv("PYTEST_ADDOPTS", "-o cache_dir=%s" % cache_dir)
|
2017-10-11 01:03:15 +08:00
|
|
|
from _pytest.config import get_config
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2017-10-11 01:03:15 +08:00
|
|
|
config = get_config()
|
|
|
|
config._preparse([], addopts=True)
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config._override_ini == ["cache_dir=%s" % cache_dir]
|
2018-01-21 02:23:08 +08:00
|
|
|
|
2018-01-24 07:13:20 +08:00
|
|
|
def test_override_ini_does_not_contain_paths(self):
|
|
|
|
"""Check that -o no longer swallows all options after it (#3103)"""
|
|
|
|
from _pytest.config import get_config
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2018-01-24 07:13:20 +08:00
|
|
|
config = get_config()
|
2018-05-23 22:48:46 +08:00
|
|
|
config._preparse(["-o", "cache_dir=/cache", "/some/test/path"])
|
|
|
|
assert config._override_ini == ["cache_dir=/cache"]
|
2018-01-24 07:13:20 +08:00
|
|
|
|
|
|
|
def test_multiple_override_ini_options(self, testdir, request):
|
2018-01-23 03:58:04 +08:00
|
|
|
"""Ensure a file path following a '-o' option does not generate an error (#3103)"""
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
**{
|
|
|
|
"conftest.py": """
|
2018-01-24 07:13:20 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addini('foo', default=None, help='some option')
|
|
|
|
parser.addini('bar', default=None, help='some option')
|
|
|
|
""",
|
2018-05-23 22:48:46 +08:00
|
|
|
"test_foo.py": """
|
2018-01-24 07:13:20 +08:00
|
|
|
def test(pytestconfig):
|
|
|
|
assert pytestconfig.getini('foo') == '1'
|
|
|
|
assert pytestconfig.getini('bar') == '0'
|
|
|
|
""",
|
2018-05-23 22:48:46 +08:00
|
|
|
"test_bar.py": """
|
2018-01-24 07:13:20 +08:00
|
|
|
def test():
|
|
|
|
assert False
|
|
|
|
""",
|
2018-05-23 22:48:46 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("-o", "foo=1", "-o", "bar=0", "test_foo.py")
|
|
|
|
assert "ERROR:" not in result.stderr.str()
|
|
|
|
result.stdout.fnmatch_lines(["collected 1 item", "*= 1 passed in *="])
|