The timeout marker for async tests is now called `async_timeout`

This commit is contained in:
Pedro Algarvio 2021-07-05 13:12:51 +01:00 committed by Megan Wilhite
parent 634a535296
commit 66d48a0c7a
2 changed files with 12 additions and 1 deletions

View file

@ -256,6 +256,10 @@ def pytest_configure(config):
"slow_test: Mark test as being slow. These tests are skipped by default unless"
" `--run-slow` is passed",
)
config.addinivalue_line(
"markers",
"async_timeout: Timeout, in seconds, for asynchronous test functions(`async def`)",
)
# "Flag" the slowTest decorator if we're skipping slow tests or not
os.environ["SLOW_TESTS"] = str(config.getoption("--run-slow"))

View file

@ -473,8 +473,13 @@ def bridge_pytest_and_runtests():
def get_test_timeout(pyfuncitem):
default_timeout = 30
marker = pyfuncitem.get_closest_marker("timeout")
marker = pyfuncitem.get_closest_marker("async_timeout")
if marker:
if marker.args:
raise pytest.UsageError(
"The 'async_timeout' marker does not accept any arguments "
"only 'seconds' as a keyword argument"
)
return marker.kwargs.get("seconds") or default_timeout
return default_timeout
@ -517,6 +522,8 @@ def pytest_pyfunc_call(pyfuncitem):
except KeyError:
loop = salt.ext.tornado.ioloop.IOLoop.current()
__tracebackhide__ = True
loop.run_sync(
CoroTestFunction(pyfuncitem.obj, testargs), timeout=get_test_timeout(pyfuncitem)
)