I want to automatically mark tests based on which fixtures they use. For instance, if a test uses a fixture named spark, I'd like to add a marker called uses_spark so that I can automatically ignore them.
I know I can use pytest_collection_modifyitems in conftest.py to add markers.
def pytest_collection_modifyitems(items):
  for item in items:
    if uses_spark_fixture(item):
      item.add_marker(pytest.mark.spark)
def uses_spark_fixture(item):
  ???
How do I implement uses_spark_fixture?
Each item stores the list of used fixtures in the fixturenames attribute. the check is thus quite simple:
def pytest_collection_modifyitems(items):
    for item in items:
        if 'spark_fixture' in item.fixturenames:
            item.add_marker(pytest.mark.spark)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With