Skip to content

Commit

Permalink
refactor(collector.py): introduce new method register_raw_fixture()
Browse files Browse the repository at this point in the history
  • Loading branch information
matosys committed Oct 12, 2024
1 parent aa0f8cf commit 58005bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/_balder/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ def __init__(self, working_dir: pathlib.Path):

self.balderglob_was_loaded = False

@staticmethod
def register_raw_fixture(fixture: Callable, level: str):
"""
allows to register a new fixture - used by decorator `@balder.fixture()`
:param level: the fixture level
:param fixture: the fixture callable itself
"""
if level not in Collector._raw_fixtures.keys():
Collector._raw_fixtures[level] = []
Collector._raw_fixtures[level].append(fixture)

@staticmethod
def register_possible_method_variation(
meth: Callable,
Expand Down
7 changes: 2 additions & 5 deletions src/_balder/decorator_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ def fixture(level: Literal['session', 'setup', 'scenario', 'variation', 'testcas
raise ValueError(f"the value of `level` must be a `str` with one of the values `{'`, `'.join(allowed_levels)}`")

def decorator_fixture(func):
# always add the fixture to FixtureManager.raw_fixtures - class determination will be done later by
# :meth:`Collector`
if level not in Collector._raw_fixtures.keys():
Collector._raw_fixtures[level] = []
Collector._raw_fixtures[level].append(func)
# always register the raw fixture in Collector - class determination will be done later by :meth:`Collector`
Collector.register_raw_fixture(func, level)

@functools.wraps(func)
def wrapper_fixture(*args, **kwargs):
Expand Down

0 comments on commit 58005bd

Please sign in to comment.