tests: revisit test_cacheprovider (#6199)
This commit is contained in:
commit
bac6eebfff
|
@ -2,7 +2,6 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
|
||||||
|
@ -60,18 +59,13 @@ class TestNewAPI:
|
||||||
@pytest.mark.filterwarnings(
|
@pytest.mark.filterwarnings(
|
||||||
"ignore:could not create cache path:pytest.PytestWarning"
|
"ignore:could not create cache path:pytest.PytestWarning"
|
||||||
)
|
)
|
||||||
def test_cache_failure_warns(self, testdir):
|
def test_cache_failure_warns(self, testdir, monkeypatch):
|
||||||
|
monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
|
||||||
cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache"))
|
cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache"))
|
||||||
mode = os.stat(cache_dir)[stat.ST_MODE]
|
mode = os.stat(cache_dir)[stat.ST_MODE]
|
||||||
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
|
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
|
||||||
try:
|
try:
|
||||||
testdir.makepyfile(
|
testdir.makepyfile("def test_error(): raise Exception")
|
||||||
"""
|
|
||||||
def test_error():
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
result = testdir.runpytest("-rw")
|
result = testdir.runpytest("-rw")
|
||||||
assert result.ret == 1
|
assert result.ret == 1
|
||||||
# warnings from nodeids, lastfailed, and stepwise
|
# warnings from nodeids, lastfailed, and stepwise
|
||||||
|
@ -178,12 +172,7 @@ def test_cache_reportheader_external_abspath(testdir, tmpdir_factory):
|
||||||
"test_cache_reportheader_external_abspath_abs"
|
"test_cache_reportheader_external_abspath_abs"
|
||||||
)
|
)
|
||||||
|
|
||||||
testdir.makepyfile(
|
testdir.makepyfile("def test_hello(): pass")
|
||||||
"""
|
|
||||||
def test_hello():
|
|
||||||
pass
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
testdir.makeini(
|
testdir.makeini(
|
||||||
"""
|
"""
|
||||||
[pytest]
|
[pytest]
|
||||||
|
@ -192,7 +181,6 @@ def test_cache_reportheader_external_abspath(testdir, tmpdir_factory):
|
||||||
abscache=external_cache
|
abscache=external_cache
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
result = testdir.runpytest("-v")
|
result = testdir.runpytest("-v")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
["cachedir: {abscache}".format(abscache=external_cache)]
|
["cachedir: {abscache}".format(abscache=external_cache)]
|
||||||
|
@ -253,36 +241,26 @@ def test_cache_show(testdir):
|
||||||
|
|
||||||
class TestLastFailed:
|
class TestLastFailed:
|
||||||
def test_lastfailed_usecase(self, testdir, monkeypatch):
|
def test_lastfailed_usecase(self, testdir, monkeypatch):
|
||||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
monkeypatch.setattr("sys.dont_write_bytecode", True)
|
||||||
p = testdir.makepyfile(
|
p = testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
def test_1():
|
def test_1(): assert 0
|
||||||
assert 0
|
def test_2(): assert 0
|
||||||
def test_2():
|
def test_3(): assert 1
|
||||||
assert 0
|
"""
|
||||||
def test_3():
|
|
||||||
assert 1
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest(str(p))
|
||||||
result.stdout.fnmatch_lines(["*2 failed*"])
|
result.stdout.fnmatch_lines(["*2 failed*"])
|
||||||
p.write(
|
p = testdir.makepyfile(
|
||||||
textwrap.dedent(
|
"""
|
||||||
"""\
|
def test_1(): assert 1
|
||||||
def test_1():
|
def test_2(): assert 1
|
||||||
assert 1
|
def test_3(): assert 0
|
||||||
|
"""
|
||||||
def test_2():
|
|
||||||
assert 1
|
|
||||||
|
|
||||||
def test_3():
|
|
||||||
assert 0
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("--lf")
|
result = testdir.runpytest(str(p), "--lf")
|
||||||
result.stdout.fnmatch_lines(["*2 passed*1 desel*"])
|
result.stdout.fnmatch_lines(["*2 passed*1 desel*"])
|
||||||
result = testdir.runpytest("--lf")
|
result = testdir.runpytest(str(p), "--lf")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"collected 3 items",
|
"collected 3 items",
|
||||||
|
@ -290,7 +268,7 @@ class TestLastFailed:
|
||||||
"*1 failed*2 passed*",
|
"*1 failed*2 passed*",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("--lf", "--cache-clear")
|
result = testdir.runpytest(str(p), "--lf", "--cache-clear")
|
||||||
result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
|
result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
|
||||||
|
|
||||||
# Run this again to make sure clear-cache is robust
|
# Run this again to make sure clear-cache is robust
|
||||||
|
@ -300,21 +278,9 @@ class TestLastFailed:
|
||||||
result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
|
result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
|
||||||
|
|
||||||
def test_failedfirst_order(self, testdir):
|
def test_failedfirst_order(self, testdir):
|
||||||
testdir.tmpdir.join("test_a.py").write(
|
testdir.makepyfile(
|
||||||
textwrap.dedent(
|
test_a="def test_always_passes(): pass",
|
||||||
"""\
|
test_b="def test_always_fails(): assert 0",
|
||||||
def test_always_passes():
|
|
||||||
assert 1
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
testdir.tmpdir.join("test_b.py").write(
|
|
||||||
textwrap.dedent(
|
|
||||||
"""\
|
|
||||||
def test_always_fails():
|
|
||||||
assert 0
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
# Test order will be collection order; alphabetical
|
# Test order will be collection order; alphabetical
|
||||||
|
@ -325,16 +291,8 @@ class TestLastFailed:
|
||||||
|
|
||||||
def test_lastfailed_failedfirst_order(self, testdir):
|
def test_lastfailed_failedfirst_order(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
**{
|
test_a="def test_always_passes(): assert 1",
|
||||||
"test_a.py": """\
|
test_b="def test_always_fails(): assert 0",
|
||||||
def test_always_passes():
|
|
||||||
assert 1
|
|
||||||
""",
|
|
||||||
"test_b.py": """\
|
|
||||||
def test_always_fails():
|
|
||||||
assert 0
|
|
||||||
""",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
# Test order will be collection order; alphabetical
|
# Test order will be collection order; alphabetical
|
||||||
|
@ -345,18 +303,13 @@ class TestLastFailed:
|
||||||
result.stdout.no_fnmatch_line("*test_a.py*")
|
result.stdout.no_fnmatch_line("*test_a.py*")
|
||||||
|
|
||||||
def test_lastfailed_difference_invocations(self, testdir, monkeypatch):
|
def test_lastfailed_difference_invocations(self, testdir, monkeypatch):
|
||||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
monkeypatch.setattr("sys.dont_write_bytecode", True)
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
test_a="""\
|
test_a="""
|
||||||
def test_a1():
|
def test_a1(): assert 0
|
||||||
assert 0
|
def test_a2(): assert 1
|
||||||
def test_a2():
|
|
||||||
assert 1
|
|
||||||
""",
|
|
||||||
test_b="""\
|
|
||||||
def test_b1():
|
|
||||||
assert 0
|
|
||||||
""",
|
""",
|
||||||
|
test_b="def test_b1(): assert 0",
|
||||||
)
|
)
|
||||||
p = testdir.tmpdir.join("test_a.py")
|
p = testdir.tmpdir.join("test_a.py")
|
||||||
p2 = testdir.tmpdir.join("test_b.py")
|
p2 = testdir.tmpdir.join("test_b.py")
|
||||||
|
@ -365,36 +318,19 @@ class TestLastFailed:
|
||||||
result.stdout.fnmatch_lines(["*2 failed*"])
|
result.stdout.fnmatch_lines(["*2 failed*"])
|
||||||
result = testdir.runpytest("--lf", p2)
|
result = testdir.runpytest("--lf", p2)
|
||||||
result.stdout.fnmatch_lines(["*1 failed*"])
|
result.stdout.fnmatch_lines(["*1 failed*"])
|
||||||
p2.write(
|
|
||||||
textwrap.dedent(
|
testdir.makepyfile(test_b="def test_b1(): assert 1")
|
||||||
"""\
|
|
||||||
def test_b1():
|
|
||||||
assert 1
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
result = testdir.runpytest("--lf", p2)
|
result = testdir.runpytest("--lf", p2)
|
||||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||||
result = testdir.runpytest("--lf", p)
|
result = testdir.runpytest("--lf", p)
|
||||||
result.stdout.fnmatch_lines(["*1 failed*1 desel*"])
|
result.stdout.fnmatch_lines(["*1 failed*1 desel*"])
|
||||||
|
|
||||||
def test_lastfailed_usecase_splice(self, testdir, monkeypatch):
|
def test_lastfailed_usecase_splice(self, testdir, monkeypatch):
|
||||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
monkeypatch.setattr("sys.dont_write_bytecode", True)
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""\
|
"def test_1(): assert 0", test_something="def test_2(): assert 0"
|
||||||
def test_1():
|
|
||||||
assert 0
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
p2 = testdir.tmpdir.join("test_something.py")
|
p2 = testdir.tmpdir.join("test_something.py")
|
||||||
p2.write(
|
|
||||||
textwrap.dedent(
|
|
||||||
"""\
|
|
||||||
def test_2():
|
|
||||||
assert 0
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines(["*2 failed*"])
|
result.stdout.fnmatch_lines(["*2 failed*"])
|
||||||
result = testdir.runpytest("--lf", p2)
|
result = testdir.runpytest("--lf", p2)
|
||||||
|
@ -436,18 +372,14 @@ class TestLastFailed:
|
||||||
def test_terminal_report_lastfailed(self, testdir):
|
def test_terminal_report_lastfailed(self, testdir):
|
||||||
test_a = testdir.makepyfile(
|
test_a = testdir.makepyfile(
|
||||||
test_a="""
|
test_a="""
|
||||||
def test_a1():
|
def test_a1(): pass
|
||||||
pass
|
def test_a2(): pass
|
||||||
def test_a2():
|
|
||||||
pass
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
test_b = testdir.makepyfile(
|
test_b = testdir.makepyfile(
|
||||||
test_b="""
|
test_b="""
|
||||||
def test_b1():
|
def test_b1(): assert 0
|
||||||
assert 0
|
def test_b2(): assert 0
|
||||||
def test_b2():
|
|
||||||
assert 0
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -492,10 +424,8 @@ class TestLastFailed:
|
||||||
def test_terminal_report_failedfirst(self, testdir):
|
def test_terminal_report_failedfirst(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
test_a="""
|
test_a="""
|
||||||
def test_a1():
|
def test_a1(): assert 0
|
||||||
assert 0
|
def test_a2(): pass
|
||||||
def test_a2():
|
|
||||||
pass
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -542,7 +472,6 @@ class TestLastFailed:
|
||||||
assert list(lastfailed) == ["test_maybe.py::test_hello"]
|
assert list(lastfailed) == ["test_maybe.py::test_hello"]
|
||||||
|
|
||||||
def test_lastfailed_failure_subset(self, testdir, monkeypatch):
|
def test_lastfailed_failure_subset(self, testdir, monkeypatch):
|
||||||
|
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
test_maybe="""
|
test_maybe="""
|
||||||
import os
|
import os
|
||||||
|
@ -560,6 +489,7 @@ class TestLastFailed:
|
||||||
env = os.environ
|
env = os.environ
|
||||||
if '1' == env['FAILIMPORT']:
|
if '1' == env['FAILIMPORT']:
|
||||||
raise ImportError('fail')
|
raise ImportError('fail')
|
||||||
|
|
||||||
def test_hello():
|
def test_hello():
|
||||||
assert '0' == env['FAILTEST']
|
assert '0' == env['FAILTEST']
|
||||||
|
|
||||||
|
@ -613,8 +543,7 @@ class TestLastFailed:
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
@pytest.mark.xfail
|
@pytest.mark.xfail
|
||||||
def test():
|
def test(): assert 0
|
||||||
assert 0
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -626,8 +555,7 @@ class TestLastFailed:
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
@pytest.mark.xfail(strict=True)
|
@pytest.mark.xfail(strict=True)
|
||||||
def test():
|
def test(): pass
|
||||||
pass
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -641,8 +569,7 @@ class TestLastFailed:
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
def test():
|
def test(): assert 0
|
||||||
assert 0
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -655,8 +582,7 @@ class TestLastFailed:
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
@pytest.{mark}
|
@pytest.{mark}
|
||||||
def test():
|
def test(): assert 0
|
||||||
assert 0
|
|
||||||
""".format(
|
""".format(
|
||||||
mark=mark
|
mark=mark
|
||||||
)
|
)
|
||||||
|
@ -694,18 +620,14 @@ class TestLastFailed:
|
||||||
# 1. initial run
|
# 1. initial run
|
||||||
test_bar = testdir.makepyfile(
|
test_bar = testdir.makepyfile(
|
||||||
test_bar="""
|
test_bar="""
|
||||||
def test_bar_1():
|
def test_bar_1(): pass
|
||||||
pass
|
def test_bar_2(): assert 0
|
||||||
def test_bar_2():
|
|
||||||
assert 0
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
test_foo = testdir.makepyfile(
|
test_foo = testdir.makepyfile(
|
||||||
test_foo="""
|
test_foo="""
|
||||||
def test_foo_3():
|
def test_foo_3(): pass
|
||||||
pass
|
def test_foo_4(): assert 0
|
||||||
def test_foo_4():
|
|
||||||
assert 0
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
testdir.runpytest()
|
testdir.runpytest()
|
||||||
|
@ -717,10 +639,8 @@ class TestLastFailed:
|
||||||
# 2. fix test_bar_2, run only test_bar.py
|
# 2. fix test_bar_2, run only test_bar.py
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
test_bar="""
|
test_bar="""
|
||||||
def test_bar_1():
|
def test_bar_1(): pass
|
||||||
pass
|
def test_bar_2(): pass
|
||||||
def test_bar_2():
|
|
||||||
pass
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(test_bar)
|
result = testdir.runpytest(test_bar)
|
||||||
|
@ -735,10 +655,8 @@ class TestLastFailed:
|
||||||
# 3. fix test_foo_4, run only test_foo.py
|
# 3. fix test_foo_4, run only test_foo.py
|
||||||
test_foo = testdir.makepyfile(
|
test_foo = testdir.makepyfile(
|
||||||
test_foo="""
|
test_foo="""
|
||||||
def test_foo_3():
|
def test_foo_3(): pass
|
||||||
pass
|
def test_foo_4(): pass
|
||||||
def test_foo_4():
|
|
||||||
pass
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(test_foo, "--last-failed")
|
result = testdir.runpytest(test_foo, "--last-failed")
|
||||||
|
@ -752,10 +670,8 @@ class TestLastFailed:
|
||||||
def test_lastfailed_no_failures_behavior_all_passed(self, testdir):
|
def test_lastfailed_no_failures_behavior_all_passed(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
def test_1():
|
def test_1(): pass
|
||||||
assert True
|
def test_2(): pass
|
||||||
def test_2():
|
|
||||||
assert True
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -777,10 +693,8 @@ class TestLastFailed:
|
||||||
def test_lastfailed_no_failures_behavior_empty_cache(self, testdir):
|
def test_lastfailed_no_failures_behavior_empty_cache(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
def test_1():
|
def test_1(): pass
|
||||||
assert True
|
def test_2(): assert 0
|
||||||
def test_2():
|
|
||||||
assert False
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("--lf", "--cache-clear")
|
result = testdir.runpytest("--lf", "--cache-clear")
|
||||||
|
@ -1022,22 +936,12 @@ class TestReadme:
|
||||||
return readme.is_file()
|
return readme.is_file()
|
||||||
|
|
||||||
def test_readme_passed(self, testdir):
|
def test_readme_passed(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile("def test_always_passes(): pass")
|
||||||
"""
|
|
||||||
def test_always_passes():
|
|
||||||
assert 1
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
testdir.runpytest()
|
testdir.runpytest()
|
||||||
assert self.check_readme(testdir) is True
|
assert self.check_readme(testdir) is True
|
||||||
|
|
||||||
def test_readme_failed(self, testdir):
|
def test_readme_failed(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile("def test_always_fails(): assert 0")
|
||||||
"""
|
|
||||||
def test_always_fails():
|
|
||||||
assert 0
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
testdir.runpytest()
|
testdir.runpytest()
|
||||||
assert self.check_readme(testdir) is True
|
assert self.check_readme(testdir) is True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue