pytest.mark usefixture vs usefixtures

Created on 13 Sep 2018  路  4Comments  路  Source: pytest-dev/pytest

I know that this is something that bites me every so often, and it recently bit a colleague of mine, however when using fixtures and marking a class/function as require a fixture, it is very unintuitive to use usefixtures when you intend to use only a single fixture.

Would it be possible to register usefixture as an alias for usefixtures to avoid this confusion and a lot of head scratching?

Especially because pytest does not seem to error when you use a non-existent mark.

fixtures marks question

All 4 comments

Especially because pytest does not seem to error when you use a non-existent mark.

As discussed on #4506, we're more likely to make it an error to use an undefined mark. From a perspective of "there should be one-- and preferably only one --obvious way to do it.", that's arguably better than an alias anyway!

@Zac-HD I would be perfectly happy with that solution too :-)

@bertjwregeer you can make pytest error out on unknown marks by passing --strict. You might decide to add this to your pytest.ini as well so you enforce it across the project:

[pytest]
addopts = --strict

@nicoddemus I had not found that while searching, but I will definitely add that to our pytest.ini files.

Was this page helpful?
0 / 5 - 0 ratings