Pytest: mark fixtures

Created on 26 Oct 2017  路  17Comments  路  Source: pytest-dev/pytest

Is it possible to mark a fixture? E.g. if I have a slow fixture, can I mark the fixture as slow, which then would propagate to mark all tests using that fixture as slow. How hard is to achieve this? Thanks!

fixtures marks enhancement

All 17 comments

this is currently not implemented and currently impossible to correctly implement due to massive issues in the mark system

then is there a mark system refactor in plan? 馃憤

yes - there was a ml thread, an the next step is killing old style marker transfer in favour of nodes owning their marks

however this still doesnt solve the fixture case as we would need to collect the complete fixture dependency/override graph and all marks within it in order to pass the data along

in addition markers like parametrize would be a pain if they where passed around that way

on top of that fixture params expansion may bring in marks that are passed in already

is there a place we can follow the progress of this beside the mailing list?

there is a project about sorting the mark issues out here in the issue tracker

@RonnyPfannschmidt @nicoddemus we the revamp of the fixtures is now possible to achieve this?

Per #3664, we have decided not to support marks on fixtures, and make this into an explicit error.

I don't see any explanation why this is the case 馃 is this a bad practice?

IIts simply an utter hell when matching various use-cases, not doing something incredible hhard and error prone is vital for the sustenance of a volunteer driven project

I guess here lies my limitation, don't know how hard it is. In my mind is just interating over all tests and all which have a fixture get a mark. This could be a final phase at the end of test collection.

Its technically impossible to do it correctly withe the current structure oof the fixture system

Just to add to @RonnyPfannschmidt's response: after collection, pytest doesn't have a map of which fixtures are used by which tests, fixtures are created lazily during test setup or even inside tests themselves using request.getfixturevalue.

What do you think of a --mark-fixture option that would add a mark to all tests using a fixture?
https://github.com/blueyed/pytest/pull/98

This allows for applying marks to tests using specific fixtures, and then
allows to (de)select them via -m, e.g. --mark-fixture foo:bar -m "not bar".

That way you basically get the originally requested feature (what I understood from skimming), but it is more dynamic in general.

as proposed, i'm strictly opposed

@RonnyPfannschmidt

as proposed, i'm strictly opposed

Care to elaborate?
It basically allows to have the commonly used boilerplate with custom --run-foo options, e.g. like you've posted in https://github.com/pytest-dev/pytest/issues/5706#issuecomment-519054604.

its the wrong place to put it(cli options) , the implementation is wrong as it auto-adds "wrong" / missing marks , furthermore its limited by name, which is limited for setups where a reshaped fixture is in use in sub-tress for example

basically its defined at the wrong place, sets details wrong and is impossible to extend

Thanks for the explanation.

its the wrong place to put it(cli options)

Why?

the implementation is wrong as it auto-adds "wrong" / missing marks

That's the point: auto-adding marks.

furthermore its limited by name, which is limited for setups where a reshaped fixture is in use in sub-tress for example

It's not meant for complex setups.

Was this page helpful?
0 / 5 - 0 ratings