Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fixture not found for parameter

I am trying to run my pytest parameterised tests.

def testConfiguration(numberOfSmall, numberOfMedium, numberOfLarge,numaValue):
   ...

@pytest.mark.parametrize("small, medium, large, numaValue, out", [
(0,0,1,0,True),
(0,0,1,1,True),
(0,0,2,0,True),
(1,1,1,0,True),
(0,1,1,0,True),
(1,0,1,0,True),
(0,1,0,0,True),
(0,1,0,1,True),
(0,2,0,0,True),
(2,2,0,0,True),
(2,1,0,0,True),
(1,0,0,0,True),
(1,0,0,1,True),
(2,0,0,0,True),
(2,0,0,1,True),
(3,0,0,0,True),
(3,0,0,1,True),
(4,0,0,0,True),
(4,1,0,0,True),
(5,0,0,0,True),
(6,0,0,0,True),
])
def testAll(small, medium, large, numaValue, out):
    assert testConfiguration(small, medium, large, numaValue) == out

However when I do I get this error in pytest.

E       fixture 'numberOfSmall' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

Note that the error is non-fatal and the rest of the program executes without fail.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why is numberOfSmall being considered a fixture? The same name is not being used as a function name.

>Solution :

It looks like testConfiguration is considered a test due to the name you have given it. All arguments you pass to a test are considered as fixtures if they don’t come from a parameterization as in your test example. To solve it, just rename your function to getTesttestConfiguration() or so.
As a side note, in python it is common to use snail case notation, not camel case notation as you have chosen.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading