[TIP] pytest
James
bjlockie at lockie.ca
Fri Oct 14 11:07:09 PDT 2016
Here is the exact code:
$ cat testconfig.py
import pytest
@pytest.fixture(scope='module')
def A(request):
return request.config.getoption("--A")
$ cat testscript.py
import pytest
skip_A = pytest.mark.skipif(
A(pytest.config.request),
reason="need --A option to run"
)
$ py.test testscript.py
============================= test session starts
==============================
platform linux2 -- Python 2.7.12, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /home/rjl/pytest, inifile:
collected 0 items / 1 errors
==================================== ERRORS
====================================
________________________ ERROR collecting testscript.py
________________________
testscript.py:4: in <module>
A(pytest.config.request),
E NameError: name 'A' is not defined
=========================== 1 error in 0.01 seconds
============================
Instead of doing
pytest.config.getoptionmore than one like this:
skip_A = pytest.mark.skipif( pytest.config.getoption("--A"),
reason="need --A option to run" )
I want to do it once in the config file.
I might want to use the value of the argument --A elsewhere so I don't
want to do getoption many times.
On 2016-10-14 01:16 PM, Bruno Oliveira wrote:
>
> Hi,
>
> After fixing the missing “pytest” import, I get this error:
>
> |foo.py:8: in <module> A(pytest.config.request), E AttributeError:
> 'Config' object has no attribute 'request' |
>
> Please make sure to post a complete example and state clearly what
> your problem is and what you are trying to accomplish.
>
> Cheers,
> Bruno.
>
>
>
> On Fri, Oct 14, 2016 at 2:03 PM James <bjlockie at lockie.ca
> <mailto:bjlockie at lockie.ca>> wrote:
>
> I have this in my config file:
> @pytest.fixture(scope='module')
> def A(request):
> return request.config.getoption("--A")
>
> skip_A = pytest.mark.skipif(
> A(pytest.config.request),
> reason="need --A option to run"
> )
>
> but when I run it, it says
> E NameError: name 'A' is not defined
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> <mailto:testing-in-python at lists.idyll.org>
> http://lists.idyll.org/listinfo/testing-in-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20161014/d19fc074/attachment.htm>
More information about the testing-in-python
mailing list