No subject


Thu Dec 12 01:15:09 PST 2013


# product is the fixture instanciated by the plugin
import pytest
class TestMyProduct:
    def test_product_name(self, product):
        if product.name != 'blabla':
            pytest.skipif('product name is blabla')
        assert name == 'blabla'

Hope this helps,
Cheers,


On Thu, Dec 12, 2013 at 4:37 PM, Christian Staffa
<Christian.Staffa at gmx.de>wrote:

>
> Hi all on the list :)
>
> Well, I am writing here a test with the pytest framework.
> I got started to write me a own plugin for my testing environment.
> This plugin generates a fixture on session level.
> Now I write a test and define a testfunctiont which uses my fixture being
> instanciated by the plugin....
> But I want to use a skipif marker when a certain condition is given
> produced by the plugin fixture.
> How can i achieve that? Any ideas? is it possible?
>
> Enough story... here is an example in essence:)
>
> # file: testfile.py
> # product is the fixture instanciated by the plugin
> import pytest
> class TestMyProduct:
>     pytest.skipif(product.name != 'blabla')
>     def test_product_name(self, product):
>         print product.name
>         assert name == 'blabla'
>
> Thanks for any comments :)
>
> Chris
>
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>

--001a11c28dcc3c9dd304ed5b050c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello Christian,<div><br></div><div>From the documentation=
 at=A0<a href=3D"http://pytest.org/latest/skipping.html#imperative-xfail-fr=
om-within-a-test-or-setup-function">http://pytest.org/latest/skipping.html#=
imperative-xfail-from-within-a-test-or-setup-function</a>, I think you will=
 have to skip the test from inside the test method:</div>

<div><br></div><div><span style=3D"font-family:arial,sans-serif;font-size:1=
3px"># product is the fixture instanciated by the plugin</span><br style=3D=
"font-family:arial,sans-serif;font-size:13px"><span style=3D"font-family:ar=
ial,sans-serif;font-size:13px">import pytest</span><br style=3D"font-family=
:arial,sans-serif;font-size:13px">

<span style=3D"font-family:arial,sans-serif;font-size:13px">class TestMyPro=
duct:</span><br style=3D"font-family:arial,sans-serif;font-size:13px"><span=
 style=3D"font-family:arial,sans-serif;font-size:13px">=A0 =A0 def test_pro=
duct_name(self, product):</span></div>

<div>=A0 =A0 =A0 =A0 if=A0<a href=3D"http://product.name/" target=3D"_blank=
" style=3D"font-size:13px;font-family:arial,sans-serif">product.name</a><sp=
an style=3D"font-size:13px;font-family:arial,sans-serif">=A0!=3D &#39;blabl=
a&#39;:</span><br style=3D"font-family:arial,sans-serif;font-size:13px">

<span style=3D"font-family:arial,sans-serif;font-size:13px">=A0 =A0 =A0 =A0=
=A0</span><span style=3D"font-size:13px;font-family:arial,sans-serif">=A0 =
=A0 pytest.skipif(&#39;product name is blabla&#39;</span><span style=3D"fon=
t-size:13px;font-family:arial,sans-serif">)</span><br style=3D"font-family:=
arial,sans-serif;font-size:13px">

<span style=3D"font-family:arial,sans-serif;font-size:13px">=A0 =A0 =A0 =A0=
 assert name =3D=3D &#39;blabla&#39;</span><br style=3D"font-family:arial,s=
ans-serif;font-size:13px"></div><div><span style=3D"font-family:arial,sans-=
serif;font-size:13px"><br>

</span></div><div><span style=3D"font-family:arial,sans-serif;font-size:13p=
x">Hope this helps,</span></div><div>Cheers,</div></div><div class=3D"gmail=
_extra"><br><br><div class=3D"gmail_quote">On Thu, Dec 12, 2013 at 4:37 PM,=
 Christian Staffa <span dir=3D"ltr">&lt;<a href=3D"mailto:Christian.Staffa@=
gmx.de" target=3D"_blank">Christian.Staffa at gmx.de</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><br>
Hi all on the list :)<br>
=A0<br>
Well, I am writing here a test with the pytest framework.<br>
I got started to write me a own plugin for my testing environment.<br>
This plugin generates=A0a fixture on session level.<br>
Now I write a test and define a testfunctiont which uses my fixture being i=
nstanciated by the plugin....<br>
But I want to use a skipif marker when=A0a certain condition is given produ=
ced by=A0the plugin fixture.<br>
How can i achieve that? Any ideas? is it possible?<br>
<br>
Enough story... here is an example in essence:)<br>
=A0<br>
# file: testfile.py<br>
# product is the fixture instanciated by the plugin<br>
import pytest<br>
class TestMyProduct:<br>
=A0 =A0 pytest.skipif(<a href=3D"http://product.name" target=3D"_blank">pro=
duct.name</a> !=3D &#39;blabla&#39;)<br>
=A0 =A0 def test_product_name(self, product):<br>
=A0 =A0 =A0 =A0 print <a href=3D"http://product.name" target=3D"_blank">pro=
duct.name</a><br>
=A0 =A0 =A0 =A0 assert name =3D=3D &#39;blabla&#39;<br>
<br>
Thanks for any comments :)<br>
<br>
Chris<br>
=A0<br>
=A0<br>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href=3D"mailto:testing-in-python at lists.idyll.org">testing-in-python at list=
s.idyll.org</a><br>
<a href=3D"http://lists.idyll.org/listinfo/testing-in-python" target=3D"_bl=
ank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</blockquote></div><br></div>

--001a11c28dcc3c9dd304ed5b050c--



More information about the testing-in-python mailing list