2014-01-29 17:20:13 +08:00
|
|
|
import pytest
|
2020-02-11 05:43:30 +08:00
|
|
|
from _pytest.config import ExitCode
|
2020-11-05 00:25:07 +08:00
|
|
|
from _pytest.monkeypatch import MonkeyPatch
|
|
|
|
from _pytest.pytester import Pytester
|
2015-07-05 01:42:22 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2019-06-03 06:32:00 +08:00
|
|
|
class SessionTests:
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_basic_testitem_events(self, pytester: Pytester) -> None:
|
|
|
|
tfile = pytester.makepyfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2010-07-27 03:15:15 +08:00
|
|
|
def test_one():
|
2008-08-16 23:26:59 +08:00
|
|
|
pass
|
|
|
|
def test_one_one():
|
|
|
|
assert 0
|
|
|
|
def test_other():
|
|
|
|
raise ValueError(23)
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestClass(object):
|
2012-07-19 15:20:14 +08:00
|
|
|
def test_two(self, someargs):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2020-11-05 00:25:07 +08:00
|
|
|
reprec = pytester.inline_run(tfile)
|
2009-05-21 20:33:09 +08:00
|
|
|
passed, skipped, failed = reprec.listoutcomes()
|
2008-08-16 23:26:59 +08:00
|
|
|
assert len(skipped) == 0
|
|
|
|
assert len(passed) == 1
|
2012-07-20 20:16:28 +08:00
|
|
|
assert len(failed) == 3
|
2017-07-17 07:25:10 +08:00
|
|
|
|
|
|
|
def end(x):
|
|
|
|
return x.nodeid.split("::")[-1]
|
|
|
|
|
2010-11-06 16:58:04 +08:00
|
|
|
assert end(failed[0]) == "test_one_one"
|
|
|
|
assert end(failed[1]) == "test_other"
|
2010-11-01 06:28:31 +08:00
|
|
|
itemstarted = reprec.getcalls("pytest_itemcollected")
|
2012-07-20 20:16:28 +08:00
|
|
|
assert len(itemstarted) == 4
|
2012-07-19 15:20:14 +08:00
|
|
|
# XXX check for failing funcarg setup
|
2017-07-17 07:25:09 +08:00
|
|
|
# colreports = reprec.getcalls("pytest_collectreport")
|
|
|
|
# assert len(colreports) == 4
|
|
|
|
# assert colreports[1].report.failed
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_nested_import_error(self, pytester: Pytester) -> None:
|
|
|
|
tfile = pytester.makepyfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2008-08-16 23:26:59 +08:00
|
|
|
import import_fails
|
|
|
|
def test_this():
|
|
|
|
assert import_fails.a == 1
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
import_fails="""
|
2010-07-27 03:15:15 +08:00
|
|
|
import does_not_work
|
2008-08-16 23:26:59 +08:00
|
|
|
a = 1
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2020-11-05 00:25:07 +08:00
|
|
|
reprec = pytester.inline_run(tfile)
|
2017-11-04 23:17:20 +08:00
|
|
|
values = reprec.getfailedcollections()
|
|
|
|
assert len(values) == 1
|
|
|
|
out = str(values[0].longrepr)
|
2018-05-23 22:48:46 +08:00
|
|
|
assert out.find("does_not_work") != -1
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_raises_output(self, pytester: Pytester) -> None:
|
|
|
|
reprec = pytester.inline_runsource(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2010-11-18 05:12:16 +08:00
|
|
|
import pytest
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_raises_doesnt():
|
2010-11-18 05:12:16 +08:00
|
|
|
pytest.raises(ValueError, int, "3")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2009-05-21 20:33:09 +08:00
|
|
|
passed, skipped, failed = reprec.listoutcomes()
|
2008-08-16 23:26:59 +08:00
|
|
|
assert len(failed) == 1
|
2020-11-05 00:25:07 +08:00
|
|
|
out = failed[0].longrepr.reprcrash.message # type: ignore[union-attr]
|
2019-03-23 00:16:08 +08:00
|
|
|
assert "DID NOT RAISE" in out
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_syntax_error_module(self, pytester: Pytester) -> None:
|
|
|
|
reprec = pytester.inline_runsource("this is really not python")
|
2017-11-04 23:17:20 +08:00
|
|
|
values = reprec.getfailedcollections()
|
|
|
|
assert len(values) == 1
|
|
|
|
out = str(values[0].longrepr)
|
2019-06-03 06:32:00 +08:00
|
|
|
assert out.find("not python") != -1
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_exit_first_problem(self, pytester: Pytester) -> None:
|
|
|
|
reprec = pytester.inline_runsource(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_one(): assert 0
|
|
|
|
def test_two(): assert 0
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
"--exitfirst",
|
|
|
|
)
|
2009-05-21 20:33:09 +08:00
|
|
|
passed, skipped, failed = reprec.countoutcomes()
|
2008-08-16 23:26:59 +08:00
|
|
|
assert failed == 1
|
|
|
|
assert passed == skipped == 0
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_maxfail(self, pytester: Pytester) -> None:
|
|
|
|
reprec = pytester.inline_runsource(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2010-05-25 22:52:09 +08:00
|
|
|
def test_one(): assert 0
|
|
|
|
def test_two(): assert 0
|
|
|
|
def test_three(): assert 0
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
"--maxfail=2",
|
|
|
|
)
|
2010-05-25 22:52:09 +08:00
|
|
|
passed, skipped, failed = reprec.countoutcomes()
|
|
|
|
assert failed == 2
|
|
|
|
assert passed == skipped == 0
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_broken_repr(self, pytester: Pytester) -> None:
|
|
|
|
p = pytester.makepyfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2010-11-13 16:05:11 +08:00
|
|
|
import pytest
|
2019-10-23 12:59:18 +08:00
|
|
|
|
|
|
|
class reprexc(BaseException):
|
|
|
|
def __str__(self):
|
|
|
|
return "Ha Ha fooled you, I'm a broken repr()."
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class BrokenRepr1(object):
|
2008-08-16 23:26:59 +08:00
|
|
|
foo=0
|
|
|
|
def __repr__(self):
|
2019-10-23 12:59:18 +08:00
|
|
|
raise reprexc
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestBrokenClass(object):
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_explicit_bad_repr(self):
|
|
|
|
t = BrokenRepr1()
|
2019-10-23 12:59:18 +08:00
|
|
|
with pytest.raises(BaseException, match="broken repr"):
|
2019-03-24 18:04:05 +08:00
|
|
|
repr(t)
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_implicit_bad_repr1(self):
|
|
|
|
t = BrokenRepr1()
|
|
|
|
assert t.foo == 1
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2020-11-05 00:25:07 +08:00
|
|
|
reprec = pytester.inline_run(p)
|
2009-05-21 20:33:09 +08:00
|
|
|
passed, skipped, failed = reprec.listoutcomes()
|
2019-03-24 18:15:40 +08:00
|
|
|
assert (len(passed), len(skipped), len(failed)) == (1, 0, 1)
|
2020-11-05 00:25:07 +08:00
|
|
|
out = failed[0].longrepr.reprcrash.message # type: ignore[union-attr]
|
2019-10-23 12:59:18 +08:00
|
|
|
assert out.find("<[reprexc() raised in repr()] BrokenRepr1") != -1
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_broken_repr_with_showlocals_verbose(self, pytester: Pytester) -> None:
|
|
|
|
p = pytester.makepyfile(
|
2019-04-19 23:54:21 +08:00
|
|
|
"""
|
|
|
|
class ObjWithErrorInRepr:
|
|
|
|
def __repr__(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def test_repr_error():
|
|
|
|
x = ObjWithErrorInRepr()
|
|
|
|
assert x == "value"
|
|
|
|
"""
|
|
|
|
)
|
2020-11-05 00:25:07 +08:00
|
|
|
reprec = pytester.inline_run("--showlocals", "-vv", p)
|
2019-04-19 23:54:21 +08:00
|
|
|
passed, skipped, failed = reprec.listoutcomes()
|
|
|
|
assert (len(passed), len(skipped), len(failed)) == (0, 0, 1)
|
2020-11-05 00:25:07 +08:00
|
|
|
entries = failed[0].longrepr.reprtraceback.reprentries # type: ignore[union-attr]
|
2019-04-19 23:54:21 +08:00
|
|
|
assert len(entries) == 1
|
|
|
|
repr_locals = entries[0].reprlocals
|
|
|
|
assert repr_locals.lines
|
|
|
|
assert len(repr_locals.lines) == 1
|
|
|
|
assert repr_locals.lines[0].startswith(
|
2019-10-23 12:59:18 +08:00
|
|
|
"x = <[NotImplementedError() raised in repr()] ObjWithErrorInRepr"
|
2019-04-19 23:54:21 +08:00
|
|
|
)
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_skip_file_by_conftest(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
conftest="""
|
2010-11-18 05:12:16 +08:00
|
|
|
import pytest
|
2010-10-14 00:41:53 +08:00
|
|
|
def pytest_collect_file():
|
2010-11-18 05:12:16 +08:00
|
|
|
pytest.skip("intentional")
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
test_file="""
|
2008-09-02 16:58:14 +08:00
|
|
|
def test_one(): pass
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2010-10-14 00:41:53 +08:00
|
|
|
try:
|
2020-11-05 00:25:07 +08:00
|
|
|
reprec = pytester.inline_run(pytester.path)
|
2019-05-14 12:51:49 +08:00
|
|
|
except pytest.skip.Exception: # pragma: no cover
|
2014-01-18 19:31:33 +08:00
|
|
|
pytest.fail("wrong skipped caught")
|
2009-05-21 20:33:09 +08:00
|
|
|
reports = reprec.getreports("pytest_collectreport")
|
2009-04-07 18:48:57 +08:00
|
|
|
assert len(reports) == 1
|
2010-07-27 03:15:15 +08:00
|
|
|
assert reports[0].skipped
|
2008-09-02 16:58:14 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
class TestNewSession(SessionTests):
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_order_of_execution(self, pytester: Pytester) -> None:
|
|
|
|
reprec = pytester.inline_runsource(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2017-11-04 23:17:20 +08:00
|
|
|
values = []
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_1():
|
2017-11-04 23:17:20 +08:00
|
|
|
values.append(1)
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_2():
|
2017-11-04 23:17:20 +08:00
|
|
|
values.append(2)
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_3():
|
2017-11-04 23:17:20 +08:00
|
|
|
assert values == [1,2]
|
2017-02-17 02:41:51 +08:00
|
|
|
class Testmygroup(object):
|
2017-11-04 23:17:20 +08:00
|
|
|
reslist = values
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_1(self):
|
|
|
|
self.reslist.append(1)
|
|
|
|
def test_2(self):
|
|
|
|
self.reslist.append(2)
|
|
|
|
def test_3(self):
|
|
|
|
self.reslist.append(3)
|
|
|
|
def test_4(self):
|
|
|
|
assert self.reslist == [1,2,1,2,3]
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2009-05-21 20:33:09 +08:00
|
|
|
passed, skipped, failed = reprec.countoutcomes()
|
2008-08-16 23:26:59 +08:00
|
|
|
assert failed == skipped == 0
|
|
|
|
assert passed == 7
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_collect_only_with_various_situations(self, pytester: Pytester) -> None:
|
|
|
|
p = pytester.makepyfile(
|
2008-08-16 23:26:59 +08:00
|
|
|
test_one="""
|
|
|
|
def test_one():
|
|
|
|
raise ValueError()
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestX(object):
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_method_one(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class TestY(TestX):
|
|
|
|
pass
|
2010-07-27 03:15:15 +08:00
|
|
|
""",
|
2009-02-27 18:18:27 +08:00
|
|
|
test_three="xxxdsadsadsadsa",
|
2018-05-23 22:48:46 +08:00
|
|
|
__init__="",
|
2008-08-16 23:26:59 +08:00
|
|
|
)
|
2020-11-05 00:25:07 +08:00
|
|
|
reprec = pytester.inline_run("--collect-only", p.parent)
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2010-11-01 06:28:31 +08:00
|
|
|
itemstarted = reprec.getcalls("pytest_itemcollected")
|
2008-08-16 23:26:59 +08:00
|
|
|
assert len(itemstarted) == 3
|
2010-07-27 03:15:15 +08:00
|
|
|
assert not reprec.getreports("pytest_runtest_logreport")
|
2009-05-21 20:33:09 +08:00
|
|
|
started = reprec.getcalls("pytest_collectstart")
|
|
|
|
finished = reprec.getreports("pytest_collectreport")
|
2010-07-27 03:15:15 +08:00
|
|
|
assert len(started) == len(finished)
|
2018-10-26 02:03:14 +08:00
|
|
|
assert len(started) == 8
|
2008-08-16 23:26:59 +08:00
|
|
|
colfail = [x for x in finished if x.failed]
|
|
|
|
assert len(colfail) == 1
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_minus_x_import_error(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(__init__="")
|
|
|
|
pytester.makepyfile(test_one="xxxx", test_two="yyyy")
|
|
|
|
reprec = pytester.inline_run("-x", pytester.path)
|
2009-05-21 20:33:09 +08:00
|
|
|
finished = reprec.getreports("pytest_collectreport")
|
2009-01-24 16:44:03 +08:00
|
|
|
colfail = [x for x in finished if x.failed]
|
|
|
|
assert len(colfail) == 1
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_minus_x_overridden_by_maxfail(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(__init__="")
|
|
|
|
pytester.makepyfile(test_one="xxxx", test_two="yyyy", test_third="zzz")
|
|
|
|
reprec = pytester.inline_run("-x", "--maxfail=2", pytester.path)
|
2016-07-20 23:20:10 +08:00
|
|
|
finished = reprec.getreports("pytest_collectreport")
|
|
|
|
colfail = [x for x in finished if x.failed]
|
|
|
|
assert len(colfail) == 2
|
|
|
|
|
2010-10-10 19:48:48 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_plugin_specify(pytester: Pytester) -> None:
|
2018-11-23 02:05:10 +08:00
|
|
|
with pytest.raises(ImportError):
|
2020-11-05 00:25:07 +08:00
|
|
|
pytester.parseconfig("-p", "nqweotexistent")
|
2017-07-17 07:25:09 +08:00
|
|
|
# pytest.raises(ImportError,
|
2013-09-30 19:14:14 +08:00
|
|
|
# "config.do_configure(config)"
|
2017-07-17 07:25:09 +08:00
|
|
|
# )
|
2010-10-10 19:48:48 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_plugin_already_exists(pytester: Pytester) -> None:
|
|
|
|
config = pytester.parseconfig("-p", "terminal")
|
2018-05-23 22:48:46 +08:00
|
|
|
assert config.option.plugins == ["terminal"]
|
2015-04-22 22:33:20 +08:00
|
|
|
config._do_configure()
|
|
|
|
config._ensure_unconfigure()
|
2010-10-10 19:48:48 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_exclude(pytester: Pytester) -> None:
|
|
|
|
hellodir = pytester.mkdir("hello")
|
|
|
|
hellodir.joinpath("test_hello.py").write_text("x y syntaxerror")
|
|
|
|
hello2dir = pytester.mkdir("hello2")
|
|
|
|
hello2dir.joinpath("test_hello2.py").write_text("x y syntaxerror")
|
|
|
|
pytester.makepyfile(test_ok="def test_pass(): pass")
|
|
|
|
result = pytester.runpytest("--ignore=hello", "--ignore=hello2")
|
2010-10-10 19:48:48 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
2012-07-20 20:16:28 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_exclude_glob(pytester: Pytester) -> None:
|
|
|
|
hellodir = pytester.mkdir("hello")
|
|
|
|
hellodir.joinpath("test_hello.py").write_text("x y syntaxerror")
|
|
|
|
hello2dir = pytester.mkdir("hello2")
|
|
|
|
hello2dir.joinpath("test_hello2.py").write_text("x y syntaxerror")
|
|
|
|
hello3dir = pytester.mkdir("hallo3")
|
|
|
|
hello3dir.joinpath("test_hello3.py").write_text("x y syntaxerror")
|
|
|
|
subdir = pytester.mkdir("sub")
|
|
|
|
subdir.joinpath("test_hello4.py").write_text("x y syntaxerror")
|
|
|
|
pytester.makepyfile(test_ok="def test_pass(): pass")
|
|
|
|
result = pytester.runpytest("--ignore-glob=*h[ea]llo*")
|
2019-02-06 00:19:24 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
|
|
|
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_deselect(pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
test_a="""
|
2018-02-10 07:44:03 +08:00
|
|
|
import pytest
|
2018-11-09 18:28:51 +08:00
|
|
|
|
2018-02-10 07:44:03 +08:00
|
|
|
def test_a1(): pass
|
2018-11-09 18:28:51 +08:00
|
|
|
|
2018-02-10 07:44:03 +08:00
|
|
|
@pytest.mark.parametrize('b', range(3))
|
|
|
|
def test_a2(b): pass
|
2018-11-09 18:28:51 +08:00
|
|
|
|
|
|
|
class TestClass:
|
|
|
|
def test_c1(self): pass
|
|
|
|
|
|
|
|
def test_c2(self): pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2020-11-05 00:25:07 +08:00
|
|
|
result = pytester.runpytest(
|
2018-11-09 18:28:51 +08:00
|
|
|
"-v",
|
|
|
|
"--deselect=test_a.py::test_a2[1]",
|
|
|
|
"--deselect=test_a.py::test_a2[2]",
|
|
|
|
"--deselect=test_a.py::TestClass::test_c1",
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
2018-02-10 07:44:03 +08:00
|
|
|
assert result.ret == 0
|
2018-11-09 18:28:51 +08:00
|
|
|
result.stdout.fnmatch_lines(["*3 passed, 3 deselected*"])
|
2018-02-10 07:44:03 +08:00
|
|
|
for line in result.stdout.lines:
|
2018-05-23 22:48:46 +08:00
|
|
|
assert not line.startswith(("test_a.py::test_a2[1]", "test_a.py::test_a2[2]"))
|
2018-02-10 07:44:03 +08:00
|
|
|
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_sessionfinish_with_start(pytester: Pytester) -> None:
|
|
|
|
pytester.makeconftest(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2013-06-10 16:09:28 +08:00
|
|
|
import os
|
2017-11-04 23:17:20 +08:00
|
|
|
values = []
|
2013-06-10 16:09:28 +08:00
|
|
|
def pytest_sessionstart():
|
2017-11-04 23:17:20 +08:00
|
|
|
values.append(os.getcwd())
|
2013-06-10 16:09:28 +08:00
|
|
|
os.chdir("..")
|
|
|
|
|
|
|
|
def pytest_sessionfinish():
|
2017-11-04 23:17:20 +08:00
|
|
|
assert values[0] == os.getcwd()
|
2013-06-10 16:09:28 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2020-11-05 00:25:07 +08:00
|
|
|
res = pytester.runpytest("--collect-only")
|
2019-06-07 18:58:51 +08:00
|
|
|
assert res.ret == ExitCode.NO_TESTS_COLLECTED
|
2018-01-18 04:02:31 +08:00
|
|
|
|
|
|
|
|
2018-02-01 05:03:24 +08:00
|
|
|
@pytest.mark.parametrize("path", ["root", "{relative}/root", "{environment}/root"])
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_rootdir_option_arg(
|
|
|
|
pytester: Pytester, monkeypatch: MonkeyPatch, path: str
|
|
|
|
) -> None:
|
|
|
|
monkeypatch.setenv("PY_ROOTDIR_PATH", str(pytester.path))
|
|
|
|
path = path.format(relative=str(pytester.path), environment="$PY_ROOTDIR_PATH")
|
|
|
|
|
|
|
|
rootdir = pytester.path / "root" / "tests"
|
|
|
|
rootdir.mkdir(parents=True)
|
|
|
|
pytester.makepyfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2018-01-25 20:57:04 +08:00
|
|
|
import os
|
|
|
|
def test_one():
|
2018-02-01 05:03:24 +08:00
|
|
|
assert 1
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-01-18 04:02:31 +08:00
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
result = pytester.runpytest(f"--rootdir={path}")
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
2018-11-09 03:35:53 +08:00
|
|
|
[
|
2020-11-05 00:25:07 +08:00
|
|
|
f"*rootdir: {pytester.path}/root",
|
2018-11-09 03:35:53 +08:00
|
|
|
"root/test_rootdir_option_arg.py *",
|
|
|
|
"*1 passed*",
|
|
|
|
]
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
2018-01-25 20:57:04 +08:00
|
|
|
|
|
|
|
|
2020-11-05 00:25:07 +08:00
|
|
|
def test_rootdir_wrong_option_arg(pytester: Pytester) -> None:
|
|
|
|
result = pytester.runpytest("--rootdir=wrong_dir")
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stderr.fnmatch_lines(
|
|
|
|
["*Directory *wrong_dir* not found. Check your '--rootdir' option.*"]
|
|
|
|
)
|