pytest-django
pytest-django copied to clipboard
Is Django Testing Tags Supported?
This is a question rather than a real issue. The documentation does not have anything about this and I couldn't find any regarding issue.
One can use tags for Django tests, is this supported?
This seems related https://github.com/pytest-dev/pytest-django/issues/516
@erayerdin you can use @pytest.mark.some_tag_here instead
It would be nice if pytest-django translated one to the other. There are usecases where it's convenient that pytest is a no code change drop in replacement.
looks like a tiny little collect hook to upgrade it to a mark
https://github.com/django/django/blob/8bcca47e8356521f52f0738d9633befd53007cae/django/test/utils.py#L844-L853
def pytest_collection_modifyitems(items):
for item in items:
for tag in getattr(item.obj, "tags", ()):
item.add_marker(pytest.mark.django_tag(tag))
I was able to get this to work (somewhat) by setting the following in conftest.py based on @graingert 's suggestion:
def pytest_collection_modifyitems(items):
for item in items:
for tag in getattr(item.obj, "tags", ()):
item.add_marker(tag)
However, this only works for @tag applied to functions - it will not work with tags on an entire TestCase class. I suspect this is because pytest markers don't work on an entire class?
we can add the following block of code to pytest_collection_modifyitems to add @tag valued as pytest markers but it raises an error if a tag is not registered in markers.
Is it a good way to go?
@bluetech do you have any idea?