@@ -270,6 +270,7 @@ class TestLastFailed:
|
||||
)
|
||||
result = testdir.runpytest(str(p), "--lf", "--cache-clear")
|
||||
result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
|
||||
assert testdir.tmpdir.join(".pytest_cache", "README.md").isfile()
|
||||
|
||||
# Run this again to make sure clear-cache is robust
|
||||
if os.path.isdir(".pytest_cache"):
|
||||
|
||||
@@ -287,13 +287,68 @@ class TestDoctests:
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest("--doctest-modules")
|
||||
result.stdout.fnmatch_lines(
|
||||
["*hello*", "006*>>> 1/0*", "*UNEXPECTED*ZeroDivision*", "*1 failed*"]
|
||||
)
|
||||
|
||||
def test_doctest_linedata_on_property(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
class Sample(object):
|
||||
@property
|
||||
def some_property(self):
|
||||
'''
|
||||
>>> Sample().some_property
|
||||
'another thing'
|
||||
'''
|
||||
return 'something'
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--doctest-modules")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*hello*",
|
||||
"*EXAMPLE LOCATION UNKNOWN, not showing all tests of that example*",
|
||||
"*1/0*",
|
||||
"*UNEXPECTED*ZeroDivision*",
|
||||
"*1 failed*",
|
||||
"*= FAILURES =*",
|
||||
"*_ [[]doctest[]] test_doctest_linedata_on_property.Sample.some_property _*",
|
||||
"004 ",
|
||||
"005 >>> Sample().some_property",
|
||||
"Expected:",
|
||||
" 'another thing'",
|
||||
"Got:",
|
||||
" 'something'",
|
||||
"",
|
||||
"*/test_doctest_linedata_on_property.py:5: DocTestFailure",
|
||||
"*= 1 failed in *",
|
||||
]
|
||||
)
|
||||
|
||||
def test_doctest_no_linedata_on_overriden_property(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
class Sample(object):
|
||||
@property
|
||||
def some_property(self):
|
||||
'''
|
||||
>>> Sample().some_property
|
||||
'another thing'
|
||||
'''
|
||||
return 'something'
|
||||
some_property = property(some_property.__get__, None, None, some_property.__doc__)
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--doctest-modules")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*= FAILURES =*",
|
||||
"*_ [[]doctest[]] test_doctest_no_linedata_on_overriden_property.Sample.some_property _*",
|
||||
"EXAMPLE LOCATION UNKNOWN, not showing all tests of that example",
|
||||
"[?][?][?] >>> Sample().some_property",
|
||||
"Expected:",
|
||||
" 'another thing'",
|
||||
"Got:",
|
||||
" 'something'",
|
||||
"",
|
||||
"*/test_doctest_no_linedata_on_overriden_property.py:None: DocTestFailure",
|
||||
"*= 1 failed in *",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
52
testing/test_main.py
Normal file
52
testing/test_main.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
from _pytest.main import ExitCode
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ret_exc",
|
||||
(
|
||||
pytest.param((None, ValueError)),
|
||||
pytest.param((42, SystemExit)),
|
||||
pytest.param((False, SystemExit)),
|
||||
),
|
||||
)
|
||||
def test_wrap_session_notify_exception(ret_exc, testdir):
|
||||
returncode, exc = ret_exc
|
||||
c1 = testdir.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def pytest_sessionstart():
|
||||
raise {exc}("boom")
|
||||
|
||||
def pytest_internalerror(excrepr, excinfo):
|
||||
returncode = {returncode!r}
|
||||
if returncode is not False:
|
||||
pytest.exit("exiting after %s..." % excinfo.typename, returncode={returncode!r})
|
||||
""".format(
|
||||
returncode=returncode, exc=exc.__name__
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
if returncode:
|
||||
assert result.ret == returncode
|
||||
else:
|
||||
assert result.ret == ExitCode.INTERNAL_ERROR
|
||||
assert result.stdout.lines[0] == "INTERNALERROR> Traceback (most recent call last):"
|
||||
|
||||
if exc == SystemExit:
|
||||
assert result.stdout.lines[-3:] == [
|
||||
'INTERNALERROR> File "{}", line 4, in pytest_sessionstart'.format(c1),
|
||||
'INTERNALERROR> raise SystemExit("boom")',
|
||||
"INTERNALERROR> SystemExit: boom",
|
||||
]
|
||||
else:
|
||||
assert result.stdout.lines[-3:] == [
|
||||
'INTERNALERROR> File "{}", line 4, in pytest_sessionstart'.format(c1),
|
||||
'INTERNALERROR> raise ValueError("boom")',
|
||||
"INTERNALERROR> ValueError: boom",
|
||||
]
|
||||
if returncode is False:
|
||||
assert result.stderr.lines == ["mainloop: caught unexpected SystemExit!"]
|
||||
else:
|
||||
assert result.stderr.lines == ["Exit: exiting after {}...".format(exc.__name__)]
|
||||
@@ -544,7 +544,7 @@ class TestAssertionWarnings:
|
||||
|
||||
def test_tuple_warning(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
"""\
|
||||
def test_foo():
|
||||
assert (1,2)
|
||||
"""
|
||||
@@ -554,48 +554,6 @@ class TestAssertionWarnings:
|
||||
result, "assertion is always true, perhaps remove parentheses?"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def create_file(testdir, return_none):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def foo(return_none):
|
||||
if return_none:
|
||||
return None
|
||||
else:
|
||||
return False
|
||||
|
||||
def test_foo():
|
||||
assert foo({return_none})
|
||||
""".format(
|
||||
return_none=return_none
|
||||
)
|
||||
)
|
||||
|
||||
def test_none_function_warns(self, testdir):
|
||||
self.create_file(testdir, True)
|
||||
result = testdir.runpytest()
|
||||
self.assert_result_warns(
|
||||
result, 'asserting the value None, please use "assert is None"'
|
||||
)
|
||||
|
||||
def test_assert_is_none_no_warn(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def foo():
|
||||
return None
|
||||
|
||||
def test_foo():
|
||||
assert foo() is None
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*1 passed in*"])
|
||||
|
||||
def test_false_function_no_warn(self, testdir):
|
||||
self.create_file(testdir, False)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*1 failed in*"])
|
||||
|
||||
|
||||
def test_warnings_checker_twice():
|
||||
"""Issue #4617"""
|
||||
|
||||
Reference in New Issue
Block a user