I'm trying to paramaterize test scenarios so I don't have to make seperate cases for each scenario like in xUnit style testing.
Here is an example from pytest that I'm trying to replicate for my own usecase.
from datetime import datetime, timedelta
testdata = [
(datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1)),
(datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1)),
]
@pytest.mark.parametrize("a,b,expected", testdata)
def test_timedistance_v0(a, b, expected):
diff = a - b
assert diff == expected
The above works just fine, But when I try to modify it for my use like seen below. I get an error that says "dump" fixture not found. I don't get what's happening. This is my first time using pytest so maybe I'm not getting something.
dump1 = load_dump(pathtodump1,pathtodump2) # load_dump can take multiple params
dump2 = load_dump(pathtodump3)
scenarios = [(dump1,{'prod_str':None}),
(dump2,{'prod_str':"123"})]
@pytest.mark.paramaterize("dump,expected_meta", scenarios)
def test_metadump_profiles(dump, expected_meta):
meta = dump.meta
assert meta.prod_str == expected_meta['prod_str']
This is the Error I get from pytest. I should also mention that when I debugged the test never runs, it fails somewhere in the paramaterize decorator.
========================================================================= ERRORS ==========================================================================
________________________________________________________ ERROR at setup of test_metadump_profiles _________________________________________________________
file /x/x/x-x/x/x/x/x/x/x/test_x.py, line 81
@pytest.mark.paramaterize("dump,expect_meta", scenarios)
def test_metadump_profiles(dump, expect_meta):
fixture 'dump' not found
available fixtures: capfd, capsys, recwarn, tmpdir_factory, tmpdir, monkeypatch, pytestconfig, record_xml_property, cache
use 'py.test --fixtures [testpath]' for help on them.
.
@pytest.mark.paramaterize
this is invalid and pytest throws an ambiguous error that makes no sense. This is caused by a spelling error...
@pytest.mark.parametrize
is the valid spelling. Stupidest bug I've pulled my hair out on. see github issue on this topic for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With