[TIP] User defined pytest parameter in setup

Brian Okken variedthoughts at gmail.com
Fri Mar 22 07:46:14 PDT 2019


Fabian,

`setup_module(module)` is a supported nose function.

I know that I'm not giving you the answer that you want, which is
essentially to be able to grab config from your `setup_module(module)` as
is.

However, you are already using pytest. Why are you holding onto
`setup_module(module)`?

If you change the signature of that function to be a proper pytest fixture,
it will then be easy.

``
@pytest.fixture(scope='module', autouse=True)
def setup_module(name):
    print(f"\nsetup_module() name: {name}")`
```

Regards,
Brian

On Fri, Mar 22, 2019 at 7:13 AM Fabian Cenedese <Cenedese at indel.ch> wrote:

> At 14:54 22.03.2019, you wrote:
>
> >Fabian,
> >Use the new `pytestconfig` fixture.
> >
> ># --------- conftest.py
> >
> >def pytest_addoption(parser):
> >    parser.addoption("--name", action="store", default="default name")
> >
> >#  ------- test_param.py
> >import pytest
> >
> >@pytest.fixture()
> >def name(pytestconfig):
> >    return pytestconfig.getoption("name")
> >
> >def test_print_name(name):
> >        print(f"\ncommand line param (name): {name}")
>
> I have already seen the example with normal test functions. But I want
> to use the value in the setup function which is defined as
>
> def setup_module(module):
>
> so I can't add the fixture there. How I can use the value in the setup?
>
> Thanks
>
> bye  Fabi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20190322/eff5b49a/attachment.htm>


More information about the testing-in-python mailing list