Even if you call the fixture as a normal function, ignoring the pytest decorator, it works fine if the signatures match.
However, if pytest itself does not exist, a detour is needed. For example, you can do the following:
try:
import pytest
except ImportError:
# provide fake pytest function to keep the script still runnable as standalone script
def null_decorator_or_decomaker(f=None, **decomaker_kwargs):
if f:
# decorator
return lambda *args, **kwargs: f(*args, **kwargs)
else:
# decomaker
def _(f):
# decomaker_kwargs can be handled
return lambda *args, **kwargs: f(*args, **kwargs)
return _
def null_decomaker(*decomaker_args, **decomaker_kwargs):
def _(f):
return lambda *args, **kwargs: f(*args, **kwargs)
return _
def null_decorator(f):
return lambda *args, **kwargs: f(*args, **kwargs)
class pytest:
fixture = staticmethod(null_decorator_or_decomaker)
class mark:
parametrize = staticmethod(null_decomaker)
# other function declarations follow if required.
\ # I'm wondering if it's related to pytest anymore, but do you want to tag it? ..
Recommended Posts