0

I have a pytest_bdd test suite, where scenarios are defined in *.feature files and the associated test steps are defined in a _test.py file. For a given group of tests, I'll have a set of *.feature files and a single _test.py file in a single folder.

When I want to run my tests against production, I want to filter so that only those scenarios marked as @production_safe are ran. I have built out the pytest_bdd_before_scenario hook in my conftest.py to skip any scenarios that do not have this marker - and that works great.

My challenge is - if I have a test function in my _test.py file that is named something like test_step_one then that function is automatically picked up by pytest and executed independently of my scenarios. Changing the python_functions parameter in pytest.ini results in none of my scenarios being picked up (because pytest_bdd under the hood creates a bunch of test_* functions). How can I block these test steps from being unintentionally picked up by pytest?

I have tried working with python_classes, python_files and python_functions in pytest.ini, but anything that blocks these step functions seems to also block picking up the pytest_bdd test functions.

  • I think it would be easier to answer your question if you post example code. Otherwise, pytest already allows you to specify a set tests to be executed by marks. Maybe it fixes already your problem. In your case to run only the tests with mark `production_safe` you would run `pytest -m production_safe`. See https://docs.pytest.org/en/7.3.x/how-to/usage.html#specifying-which-tests-to-run – mattefrank Jun 14 '23 at 16:47

0 Answers0