Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@fixture(scope=Scope.Global)
def g():
yield "g"
events.append("teardown g")
def _(cache: FixtureCache = cache, t: Test = my_test):
cache.teardown_fixtures_for_scope(Scope.Test, t.id)
fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Test, t.id)
expect(fixtures_at_scope).equals({})
def _(f=exception_raising_fixture):
cache = FixtureCache()
cache.cache_fixture(f, "test_id")
expect(cache.get(f.key, Scope.Test, "test_id")).equals(f)
@fixture(scope=Scope.Module)
def m():
yield "m"
events.append("teardown m")
generated_test(**resolved_vals)
outcome = (
TestOutcome.XPASS if marker == "XFAIL" else TestOutcome.PASS
)
yield generated_test.get_result(outcome)
except FixtureError as e:
yield generated_test.get_result(TestOutcome.FAIL, e)
continue
except Exception as e:
outcome = (
TestOutcome.XFAIL if marker == "XFAIL" else TestOutcome.FAIL
)
yield generated_test.get_result(outcome, e)
finally:
self.cache.teardown_fixtures_for_scope(
Scope.Test, scope_key=generated_test.id
)
if num_tests_per_module[generated_test.path] == 0:
self.cache.teardown_fixtures_for_scope(
Scope.Module, scope_key=generated_test.path
)
self.cache.teardown_global_fixtures()
yield generated_test.get_result(outcome)
except FixtureError as e:
yield generated_test.get_result(TestOutcome.FAIL, e)
continue
except Exception as e:
outcome = (
TestOutcome.XFAIL if marker == "XFAIL" else TestOutcome.FAIL
)
yield generated_test.get_result(outcome, e)
finally:
self.cache.teardown_fixtures_for_scope(
Scope.Test, scope_key=generated_test.id
)
if num_tests_per_module[generated_test.path] == 0:
self.cache.teardown_fixtures_for_scope(
Scope.Module, scope_key=generated_test.path
)
self.cache.teardown_global_fixtures()