[TIP] combining markers in pytest
holger krekel
holger at merlinux.eu
Sat Oct 20 01:10:35 PDT 2012
Hi Chris,
On Fri, Oct 19, 2012 at 17:40 -0400, Pella,Chris wrote:
> I'm trying to find out if we can combine markers in a Boolean way using pytest. Let's say we have some tests that can be marked as 'regression', or 'smoke', or 'nightly_build'. We have some other tests that are platform-specific and we mark as linux_x86_32 , solaris_sparc_32 etc...
> Is there a way to combine these so that we can say include a linux_x86_32 test as part of the nightly build?
> If you stack the markers like below it will 'or' the markers so that it will always run if py.test -m nightly is used even if linux_x86_32 is not set:
> @pytest.marker.nightly
> @pytest.marker.linux_x86_32
> def test_me():
> ...
>
> What is the best way to select tests when there are multiple pre-conditions involved? Should we just be organizing test classes differently (this would involve code duplication and doesn't appeal) ? We are setting up automated testing using Jenkins over multiple client platforms and with multiple test targets (we make embedded systems), and want to designate different types of test runs.
the "-m" option allows to specify an expression, so you can do:
py.test -m "nightly and linux_x86_32"
or
py.test -m "nightly and not linux_x86_32"
etc. it's really an arbitrary expression - marker names that
are not present will yield a False value. If the documentation
or help strings are not clear enough about it, feedback/reporting an issue
is welcome!
HTH,
holger
> Chris
>
>
>
> The information contained in this electronic mail transmission
> may be privileged and confidential, and therefore, protected
> from disclosure. If you have received this communication in
> error, please notify us immediately by replying to this
> message and deleting it from your computer without copying
> or disclosing it.
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
More information about the testing-in-python
mailing list