allure-framework / allure-python

Allure integrations for Python test frameworks
https://allurereport.org/
Apache License 2.0
713 stars 233 forks source link

Excluding allure-labels in pytest run #812

Open ushankax opened 2 months ago

ushankax commented 2 months ago

I'm submitting a ...

What is the current behavior?

We have CLI param --allure-label and its possible to INCLUDE labels. Like --allure-label method=AnyMethod and it works

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

But I decided to try to exclude from run tests with @allure.manual(True) decorator and came across a bunch of things:

  1. You can't even include by label if your value (but it's default value) is a bool type. Example: if you set --allure-label ALLURE_MANUAL=True in CLI so it will deselect everything.
  2. But I could find an interesting moment: if to write decorator like @allure.manual('True') and set the same --allure-label ALLURE_MANUAL=True in CLI -- it works and manual tests will be selected.

What is the expected behavior?

I want not just include labels, but also exclude. Something like --allure-label "not ALLURE_MANUAL=True"

What is the motivation / use case for changing the behavior?

We write tests as code and we dont need manual test cases in allure report. With this feature we will be able to run night tests and they will be closed automatically in allure testOps.

Please tell us about your environment:

delatrie commented 1 month ago

Hi, @ushankax. Thank you for the feature request. That's something that might be implemented in the future. Sorry for not giving any specific date.

That said, it's much quicker to implement such specific filtering in your own code. Just put the following in your conftest.py:

from allure_commons.types import LabelType
from allure_pytest.utils import allure_label

def pytest_addoption(parser):
    parser.addoption('--exclude-manual', action='store_true')

def pytest_collection_modifyitems(config, items):
    if config.getoption("--exclude-manual"):
        items[:] = filter(
            lambda item: not any(allure_label(item, LabelType.MANUAL)),
            items,
        )

Then, exclude manual tests by invoking pytest --exclude-manual.