You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a possibility to leverage the python annotation system to implement very modular and structured fixtures. I hope the following illustrates the draft of the idea.
fromtypingimportCallablefromdataclassesimportdataclass## Somewhere in the pytest internals would be:defsatisfy_the_annotations(f: Callable):
sig=inspect.signature(f)
params=sig.bind(**{n: satisfy_the_annotations(p.annotation)
forn, pinsig.parameters.items()})
returnf(*params.args, **params.kwargs)
defrun_test(f: Callable):
retval=satisfy_the_annotations(f)
return"PASSED"## In the file with the tests: @dataclassclassName:
val: int=0def__init__(self):
self.__class__.val+=1self.val=self.__class__.val@dataclassclassSurname:
pass@dataclassclassFixture:
name: Name@dataclassclassExtendedFixture(Fixture):
surname: Surnamepassdeftest_function_with_annotations(somefixture: Fixture,
otherfixture: Fixture,
extended: ExtendedFixture,
aaa="ddd"):
print(somefixture, otherfixture, extended, aaa)
assertisinstance(somefixture.name, Name)
run_test(test_function_with_annotations)
The text was updated successfully, but these errors were encountered:
There is a possibility to leverage the python annotation system to implement very modular and structured fixtures. I hope the following illustrates the draft of the idea.
The text was updated successfully, but these errors were encountered: