mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Remove custom fixture scope ordering code
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
8fc4738ead
commit
d8cb80216e
1 changed files with 1 additions and 100 deletions
|
@ -10,7 +10,7 @@ import re
|
|||
import shutil
|
||||
import stat
|
||||
import sys
|
||||
from functools import lru_cache, partial, wraps
|
||||
from functools import lru_cache
|
||||
from unittest import TestCase # pylint: disable=blacklisted-module
|
||||
|
||||
import _pytest.logging
|
||||
|
@ -448,8 +448,6 @@ def pytest_collection_modifyitems(config, items):
|
|||
groups_collection_modifyitems(config, items)
|
||||
from_filenames_collection_modifyitems(config, items)
|
||||
|
||||
log.warning("Mofifying collected tests to keep track of fixture usage")
|
||||
|
||||
timeout_marker_tests_paths = (
|
||||
str(PYTESTS_DIR / "pkg"),
|
||||
str(PYTESTS_DIR / "scenarios"),
|
||||
|
@ -478,103 +476,6 @@ def pytest_collection_modifyitems(config, items):
|
|||
# Default to counting only the test execution for the timeouts, ie,
|
||||
# withough including the fixtures setup time towards the timeout.
|
||||
item.add_marker(pytest.mark.timeout(90, func_only=True))
|
||||
for fixture in item.fixturenames:
|
||||
if fixture not in item._fixtureinfo.name2fixturedefs:
|
||||
continue
|
||||
for fixturedef in item._fixtureinfo.name2fixturedefs[fixture]:
|
||||
if fixturedef.scope != "package":
|
||||
continue
|
||||
try:
|
||||
fixturedef.finish.__wrapped__
|
||||
except AttributeError:
|
||||
original_func = fixturedef.finish
|
||||
|
||||
def wrapper(func, fixturedef):
|
||||
@wraps(func)
|
||||
def wrapped(self, request, nextitem=False):
|
||||
try:
|
||||
return self._finished
|
||||
except AttributeError:
|
||||
if nextitem:
|
||||
fpath = pathlib.Path(self.baseid).resolve()
|
||||
tpath = pathlib.Path(
|
||||
nextitem.fspath.strpath
|
||||
).resolve()
|
||||
try:
|
||||
tpath.relative_to(fpath)
|
||||
# The test module is within the same package that the fixture is
|
||||
if (
|
||||
not request.session.shouldfail
|
||||
and not request.session.shouldstop
|
||||
):
|
||||
log.debug(
|
||||
"The next test item is still under the"
|
||||
" fixture package path. Not"
|
||||
" terminating %s",
|
||||
self,
|
||||
)
|
||||
return
|
||||
except ValueError:
|
||||
pass
|
||||
log.debug("Finish called on %s", self)
|
||||
try:
|
||||
return func(request)
|
||||
except (
|
||||
BaseException # pylint: disable=broad-except
|
||||
) as exc:
|
||||
pytest.fail(
|
||||
"Failed to run finish() on {}: {}".format(
|
||||
fixturedef, exc
|
||||
),
|
||||
pytrace=True,
|
||||
)
|
||||
finally:
|
||||
self._finished = True
|
||||
|
||||
return partial(wrapped, fixturedef)
|
||||
|
||||
fixturedef.finish = wrapper(fixturedef.finish, fixturedef)
|
||||
try:
|
||||
fixturedef.finish.__wrapped__
|
||||
except AttributeError:
|
||||
fixturedef.finish.__wrapped__ = original_func
|
||||
|
||||
|
||||
@pytest.hookimpl(trylast=True, hookwrapper=True)
|
||||
def pytest_runtest_protocol(item, nextitem):
|
||||
"""
|
||||
implements the runtest_setup/call/teardown protocol for
|
||||
the given test item, including capturing exceptions and calling
|
||||
reporting hooks.
|
||||
|
||||
:arg item: test item for which the runtest protocol is performed.
|
||||
|
||||
:arg nextitem: the scheduled-to-be-next test item (or None if this
|
||||
is the end my friend). This argument is passed on to
|
||||
:py:func:`pytest_runtest_teardown`.
|
||||
|
||||
:return boolean: True if no further hook implementations should be invoked.
|
||||
|
||||
|
||||
Stops at first non-None result, see :ref:`firstresult`
|
||||
"""
|
||||
request = item._request
|
||||
used_fixture_defs = []
|
||||
for fixture in item.fixturenames:
|
||||
if fixture not in item._fixtureinfo.name2fixturedefs:
|
||||
continue
|
||||
for fixturedef in reversed(item._fixtureinfo.name2fixturedefs[fixture]):
|
||||
if fixturedef.scope != "package":
|
||||
continue
|
||||
used_fixture_defs.append(fixturedef)
|
||||
try:
|
||||
# Run the test
|
||||
yield
|
||||
finally:
|
||||
for fixturedef in used_fixture_defs:
|
||||
fixturedef.finish(request, nextitem=nextitem)
|
||||
del request
|
||||
del used_fixture_defs
|
||||
|
||||
|
||||
def pytest_markeval_namespace(config):
|
||||
|
|
Loading…
Add table
Reference in a new issue