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
For pytest-django I was looking into having a prefix of "django_" for all fixtures, and adding compat warning for the old ones.
I came up with the following, but it has some issues:
needs proper stacklevel
is the generator test sane?
Can this be done easier?
I think it might make sense for pytest to provide some help in this regard, and there is lilkely something that I have not found..?
classPytestDjangoPrefixDeprecationWarning(DeprecationWarning):
pass# Copied from pytest.defiscoroutinefunction(func):
returngetattr(func, "_is_coroutine", False) or (
hasattr(inspect, "iscoroutinefunction") andinspect.iscoroutinefunction(func)
)
# Copied from pytest.defis_generator(func):
genfunc=inspect.isgeneratorfunction(func)
returngenfuncandnotiscoroutinefunction(func)
defcompat_prefix_warning(new_fixture):
# TODO: get stacklevel for warning to point at test..# Non-complete code via pytest-pdb:# https://github.com/fschulze/pytest-pdb/blob/88bb88a20c6e69ec4e3da4a2d6cabac9cfb2cd86/pytest_pdb.py#L7-L16# For handling fixture setup: https://github.com/fschulze/pytest-pdb/issues/7new_name=new_fixture.__name__assertnew_name.startswith("django_")
orig_func=new_fixture.__pytest_wrapped__.objifis_generator(orig_func):
@pytest.fixture@wraps(orig_func)defwrapper(**kwargs):
msg="Please use fixture %s instead of %s."% (new_name, new_name[7:])
warnings.warn(PytestDjangoPrefixDeprecationWarning(msg), stacklevel=2)
yieldfromorig_func(**kwargs)
else:
@pytest.fixture@wraps(orig_func)defwrapper(**kwargs):
msg="Please use fixture %s instead of %s."% (new_name, new_name[7:])
warnings.warn(PytestDjangoPrefixDeprecationWarning(msg), stacklevel=2)
returnorig_func(**kwargs)
returnwrapper# For backward compatibility.settings=compat_prefix_warning(django_settings)
db=compat_prefix_warning(django_db)
The text was updated successfully, but these errors were encountered:
For pytest-django I was looking into having a prefix of "django_" for all fixtures, and adding compat warning for the old ones.
I came up with the following, but it has some issues:
Can this be done easier?
I think it might make sense for pytest to provide some help in this regard, and there is lilkely something that I have not found..?
The text was updated successfully, but these errors were encountered: