When I declare a marker in pytest.ini having a parameter, this is not recognized in pytest-bdd feature file. Markers without parameters seem to work fine.
[pytest]
markers =
swr(issue1): link to Software Requirement
smoke: Smoke Test component
Simple feature file works fine with @smoke:
Feature: Trivial Example
@smoke
Scenario: Add a number to another number
Given 7 is set
When 9 is added
Then new value is 16
Fails with @swr("123"):
Feature: Trivial Example
@swr("123")
Scenario: Add a number to another number
Given 7 is set
When 9 is added
Then new value is 16
Failure is a warning:
../../../../../.local/lib/python3.10/site-packages/pytest_bdd/plugin.py:127
/home/parallels/.local/lib/python3.10/site-packages/pytest_bdd/plugin.py:127: PytestUnknownMarkWarning: Unknown pytest.mark.swr("123") - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
mark = getattr(pytest.mark, tag)
Taking a look in the known issues in the repository I stumbled upon something that is related. The developer mentions there is a hook available which is seen here.
In the
conftest.pywe can then do the following:Then we can just register the marker as
swrand the hook should automatically parametrize the function as needed. It usesastto parse the marker and dynamically create the new marker. Shown below is whatmarklooks like when running withswrorswr("123").Take note of
MarkDecoratorin the output for each of the calls.