Merge 807c014518
into f426c0b35a
This commit is contained in:
commit
58728177f9
|
@ -1,7 +1,3 @@
|
|||
from typing import final
|
||||
|
||||
|
||||
@final
|
||||
class UsageError(Exception):
|
||||
"""Error in pytest usage or invocation."""
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ from _pytest.compat import safe_isclass
|
|||
from _pytest.config import Config
|
||||
from _pytest.config import hookimpl
|
||||
from _pytest.config.argparsing import Parser
|
||||
from _pytest.config.exceptions import UsageError
|
||||
from _pytest.deprecated import check_ispytest
|
||||
from _pytest.fixtures import FixtureDef
|
||||
from _pytest.fixtures import FixtureRequest
|
||||
|
@ -77,7 +78,6 @@ from _pytest.scope import Scope
|
|||
from _pytest.stash import StashKey
|
||||
from _pytest.warning_types import PytestCollectionWarning
|
||||
from _pytest.warning_types import PytestReturnNotNoneWarning
|
||||
from _pytest.warning_types import PytestUnhandledCoroutineWarning
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -138,6 +138,16 @@ def pytest_configure(config: Config) -> None:
|
|||
)
|
||||
|
||||
|
||||
@final
|
||||
class PytestUnhandledCoroutineError(UsageError):
|
||||
"""An unraisable exception resulted in an error.
|
||||
|
||||
Unraisable exceptions are exceptions raised in :meth:`__del__ <object.__del__>`
|
||||
implementations and similar situations when the exception cannot be raised
|
||||
as normal.
|
||||
"""
|
||||
|
||||
|
||||
def async_warn_and_skip(nodeid: str) -> None:
|
||||
msg = "async def functions are not natively supported and have been skipped.\n"
|
||||
msg += (
|
||||
|
@ -148,7 +158,9 @@ def async_warn_and_skip(nodeid: str) -> None:
|
|||
msg += " - pytest-tornasync\n"
|
||||
msg += " - pytest-trio\n"
|
||||
msg += " - pytest-twisted"
|
||||
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))
|
||||
raise PytestUnhandledCoroutineError(
|
||||
msg.format(nodeid)
|
||||
) # TODO: This is the warning to look at
|
||||
skip(reason="async def function and no async plugin installed (see warnings)")
|
||||
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ class PytestExperimentalApiWarning(PytestWarning, FutureWarning):
|
|||
|
||||
|
||||
@final
|
||||
class PytestUnhandledCoroutineWarning(PytestReturnNotNoneWarning):
|
||||
class PytestUnhandledCoroutineWarning(PytestReturnNotNoneWarning): # TODO: look at this
|
||||
"""Warning emitted for an unhandled coroutine.
|
||||
|
||||
A coroutine was encountered when collecting test functions, but was not
|
||||
|
|
|
@ -1233,7 +1233,7 @@ def test_usage_error_code(pytester: Pytester) -> None:
|
|||
assert result.ret == ExitCode.USAGE_ERROR
|
||||
|
||||
|
||||
def test_warn_on_async_function(pytester: Pytester) -> None:
|
||||
def test_error_on_async_function(pytester: Pytester) -> None: # TODO: Change this
|
||||
# In the below we .close() the coroutine only to avoid
|
||||
# "RuntimeWarning: coroutine 'test_2' was never awaited"
|
||||
# which messes with other tests.
|
||||
|
@ -1249,23 +1249,19 @@ def test_warn_on_async_function(pytester: Pytester) -> None:
|
|||
return coro
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest("-Wdefault")
|
||||
result = pytester.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"test_async.py::test_1",
|
||||
"test_async.py::test_2",
|
||||
"test_async.py::test_3",
|
||||
"*test_async.py::test_1*",
|
||||
"*test_async.py::test_2*",
|
||||
"*test_async.py::test_3*",
|
||||
"*async def functions are not natively supported*",
|
||||
"*3 skipped, 3 warnings in*",
|
||||
]
|
||||
)
|
||||
# ensure our warning message appears only once
|
||||
assert (
|
||||
result.stdout.str().count("async def functions are not natively supported") == 1
|
||||
)
|
||||
result.assert_outcomes(failed=3)
|
||||
|
||||
|
||||
def test_warn_on_async_gen_function(pytester: Pytester) -> None:
|
||||
def test_error_on_async_gen_function(pytester: Pytester) -> None: # TODO: Change this
|
||||
pytester.makepyfile(
|
||||
test_async="""
|
||||
async def test_1():
|
||||
|
@ -1276,20 +1272,15 @@ def test_warn_on_async_gen_function(pytester: Pytester) -> None:
|
|||
return test_2()
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest("-Wdefault")
|
||||
result = pytester.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"test_async.py::test_1",
|
||||
"test_async.py::test_2",
|
||||
"test_async.py::test_3",
|
||||
"*test_async.py::test_1*",
|
||||
"*test_async.py::test_2*",
|
||||
"*test_async.py::test_3*",
|
||||
"*async def functions are not natively supported*",
|
||||
"*3 skipped, 3 warnings in*",
|
||||
]
|
||||
)
|
||||
# ensure our warning message appears only once
|
||||
assert (
|
||||
result.stdout.str().count("async def functions are not natively supported") == 1
|
||||
)
|
||||
|
||||
|
||||
def test_pdb_can_be_rewritten(pytester: Pytester) -> None:
|
||||
|
|
|
@ -1313,7 +1313,7 @@ def test_pdb_teardown_skipped_for_classes(
|
|||
assert tracked == []
|
||||
|
||||
|
||||
def test_async_support(pytester: Pytester) -> None:
|
||||
def test_async_support(pytester: Pytester) -> None: # TODO: Change this
|
||||
pytest.importorskip("unittest.async_case")
|
||||
|
||||
pytester.copy_example("unittest/test_unittest_asyncio.py")
|
||||
|
|
Loading…
Reference in New Issue