Python Testing with pytest: pytest now requires markers to be declared (downloadable code)

Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not declared in a pytest.ini file. This was allowed when the book was published. But recent versions of pytest will issue a warning with undeclared markers.

To fix the warning, add this small pytest.ini file to any tests directory that’s causing a problem:

[pytest]
markers =
    smoke
    get
2 Likes

Hi there,
still not working with your update.
is it possible to update all the codes and upload to Github ?

thanks,

pytest.ini is in the source code zip file available on the pragprog website, but it seems to be in the wrong directory.

I found it as “ch2/tasks_prog/tests/pytest.ini” and on moving it up one level to “ch2/tasks_prog/pytest.ini” it suddenly works, regardless which directory I’m in when I run pytest.

I haven’t checked other chapter directories yet, but worth having a look at that.