(
old_item: _pytest.Item, parent: Any, fn: Callable[..., Any]
)
| 108 | |
| 109 | |
| 110 | def _sub_function( |
| 111 | old_item: _pytest.Item, parent: Any, fn: Callable[..., Any] |
| 112 | ) -> _pytest.Item: |
| 113 | # Directly execute the cell, since this means it's a toplevel function with no deps. |
| 114 | # Or a cell where which we already wrapped in skip. |
| 115 | if isinstance(old_item.obj, Cell): |
| 116 | return old_item |
| 117 | |
| 118 | import pytest # type: ignore |
| 119 | from _pytest.fixtures import FuncFixtureInfo # type: ignore |
| 120 | |
| 121 | fixtureinfo = old_item._fixtureinfo |
| 122 | param_names: set[str] = set() |
| 123 | |
| 124 | if hasattr(old_item, "callspec") and old_item.callspec: |
| 125 | params: dict[str, Any] = old_item.callspec.params |
| 126 | param_names = set(params.keys()) |
| 127 | |
| 128 | def make_test_func( |
| 129 | func_JYWB: Callable[..., Any], param_dict: dict[str, Any] |
| 130 | ) -> Callable[[], Any]: |
| 131 | # note _JYWB is a suffix to easily detect in stack trace for |
| 132 | # removal. |
| 133 | # Also no functools.wraps(func) because we need the empty |
| 134 | # call signature |
| 135 | def test_wrapper(*args: Any, **kwargs: Any) -> Any: |
| 136 | return func_JYWB(*args, **kwargs, **param_dict) |
| 137 | |
| 138 | # but copy attributes from the original function |
| 139 | test_wrapper.__name__ = func_JYWB.__name__ |
| 140 | test_wrapper.__module__ = func_JYWB.__module__ |
| 141 | return test_wrapper |
| 142 | |
| 143 | fn = make_test_func(fn, params) |
| 144 | |
| 145 | # Filter out parametrized args from fixtureinfo since they're baked in |
| 146 | fixtureinfo = FuncFixtureInfo( |
| 147 | argnames=tuple( |
| 148 | a for a in fixtureinfo.argnames if a not in param_names |
| 149 | ), |
| 150 | initialnames=tuple( |
| 151 | a for a in fixtureinfo.initialnames if a not in param_names |
| 152 | ), |
| 153 | names_closure=[ |
| 154 | a for a in fixtureinfo.names_closure if a not in param_names |
| 155 | ], |
| 156 | name2fixturedefs={ |
| 157 | k: v |
| 158 | for k, v in fixtureinfo.name2fixturedefs.items() |
| 159 | if k not in param_names |
| 160 | }, |
| 161 | ) |
| 162 | |
| 163 | pyfn = pytest.Function.from_parent( |
| 164 | parent, |
| 165 | name=old_item.name, |
| 166 | callobj=fn, |
| 167 | fixtureinfo=fixtureinfo, # Preserve fixture metadata (minus params) |
no test coverage detected
searching dependent graphs…