'How do I allow @pytest.mark.parametrize(argnames, argvalues) to dynamically modify argvalues according to fixture?
I have two fixtures. One is called version carrying parameters. Another one is called data and it uses the version fixture.
Now I have a testcase called test_filter. It's decorated by @pytest.mark.parametrize("a, b", test_data["test_obj"]).
The problem is the test_data I want to read from a file according to its version.
But @pytest.mark.parametrize will collect test_data at the collection stage, the modification cannot be done. How do I modify test_data dynamically?
import pytest
@pytest.fixture(params=["v1", "v2"])
def version(request):
return request.param
@pytest.fixture
def data(version):
return Data(version)
class TestData:
test_data = {
"test_obj": ""
} ## read file according version
@pytest.mark.parametrize("a, b", test_data["test_obj"])
def test_filter(self, data, a, b):
assert data.filter(a) == b
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
