[TIP] pytest: markers as functions
stony8de at gmail.com
Sun Jan 27 21:48:27 PST 2013
On Jan 26, 2013 3:07 PM, "holger krekel" <holger at merlinux.eu> wrote:
> On Sat, Jan 26, 2013 at 14:08 +0100, Alexander Steinert wrote:
> > @pytest.marker
> > def verifies(request, requirement):
> > ....
> > ....
> > @verifies("Requirement 42")
> > def test_42():
> > assert False
> > ....
> > $ py.test . --show-verifications
> > test_42 vierifies Requirement 42
> > By reading the fine manual I assume that this would be a feature
> > What would come closest to it using the current pytest?
> I have an unfinished patch which allows roughly the above. However, it's
> not providing "request" and i am not sure how you would use it above.
> Certainly at collection time it cannot be the "request" object that's used
> during fixture setup.
I see. I need some object to collect which test verifies which
requirement. That could be done without pytest help using a module level
dict in my conftest.py. But I think that the marker decorated by
pytest.marker (or pytest.markdefinition) would benefit from getting the
marked test function (or something else) as its first argument so that
it can get/derive the test name unique to the test session.
Does pytest provide a hook just after collection took place? There I
could evaluate my --show-verifications option, show my output and exit
> In any case, here is a test taken from the unifinished patch which
> the intended API.
> def test_1():
> assert test_1.mymarker.getarg("arg1") == 42
What about test_1.mymarker.pargs and test_1.mymarker.kwargs, in case
they should be forwarded somewhere? Anyway, for my use case, I wouldn't
need access to the marker from the test itself.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python