Reputation: 265
when I tried to use mark.parametrize along with other decorators as follows:
@pytest.fixture(autouse=True)
def some_fixture()
db = create_db()
yield db
db.close()
@pytest.mark.parametrize('id, expected',[(1,1),(2,2)])
@mock.patch('some_module')
def some_test(mock_module, id, expected, db):
mock_module.function.return_value = 1
connection = db.connection()
assert expected my_function(id, connection)
I have two questions:
general one: what is the natural order to put the arguments and to order the decorators in case of having more than one?
specific to above code: why do I get error: missing 2 required positional arguments
for both id
and expected
even though they are supplied as shown?
Upvotes: 1
Views: 3420
Reputation: 261
When using patch, parametrize and fixtures altogether, the order is important: Fists should be mention patched values, in reverse order, then parametrized values and fixtures in the end in any order.
@pytest.fixture
def some_fixture1()
pass
@pytest.fixture
def some_fixture2()
pass
@pytest.mark.parametrize('id, expected',[(1,1),(2,2)])
@mock.patch('some_module1')
@mock.patch('some_module2')
@mock.patch('some_module3')
def some_test(
some_module3,
some_module2,
some_module1,
id,
expected,
some_fixture1,
some_fixture2,
):
pass
Upvotes: 2