August 2018
Beginner
160 pages
4h 8m
English
Fixtures can also be parametrized directly. When a fixture is parametrized, all tests that use the fixture will now run multiple times, once for each parameter. This is an excellent tool to use when we have variants of a fixture and each test that uses the fixture should also run with all variants.
In the previous chapter, we saw an example of parametrization using multiple implementations of a serializer:
@pytest.mark.parametrize( "serializer_class", [JSONSerializer, XMLSerializer, YAMLSerializer],)class Test: def test_quantity(self, serializer_class): serializer = serializer_class() quantity = Quantity(10, "m") data = serializer.serialize_quantity(quantity) new_quantity = serializer.deserialize_quantity(data) assert ...
Read now
Unlock full access