How Can I Access Al The Markers In A Pytest Fixture?
I'm using pytest and I want to tag my tests with markers which will specify to a fixture which page to load in my driver. This works easily with the behave context object, but I ca
Solution 1:
There's either request.node.own_markers
or request.node.iter_markers()
which will give you access to the markers of the node
for example:
(Pdb) request.node.own_markers[Mark(name='hello', args=(), kwargs={})]
(Pdb) request.node.iter_markers()
<generator object Node.iter_markers.<locals>.<genexpr> at 0x7f3a601a60a0>
(Pdb) plist(request.node.iter_markers())
[Mark(name='hello', args=(), kwargs={})]
these two will differ (for example) if markers are applied on a higher scope
there's some examples in the markers docs (none that use request
but item
is the same in those examples (which use pytest hooks instead))
Solution 2:
I found the answer by playing around. The fixture was marked 'scope=module' while my only the test function had the marker. It was therefore out of scope for the fixture, hence the empty list. When I made the fixture have default scope, the marker was found.
Post a Comment for "How Can I Access Al The Markers In A Pytest Fixture?"