Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Pytest Style topology/test_tprparser.py #1606
Would it be possible to parametrize the classes? It was not possible to generate the test classes with nose, but hopefully it is possible with pytest. It would drastically reduce the code repetition.
@utkbansal Sorry I do not have the time right now to look at the details of how to parametrize a class. But if you really have to use the fixture, could the fixture be defined only once in the base class and return the class attribute? It makes inheritance much easier: you just have to create the class with the right class attribute and not to overwrite a method.
@utkbansal something like this should work:
# in base.py @pytest.fixture def top(self, request): with self.parser(request.cls.filename) as p: yield p.parse() # in test_crd class TestCRDParser(ParserBase): filename = CRD
referenced this pull request
Aug 23, 2017
So, if I well understand, we now overwrite the
ref_filename class attribute and everything works as before. But if we want to run the tests on a bunch of different files, we overwrite the
filename fixture. Looks fine to me. In the tests for the TPR format, it really reduces the code duplication.
Yes that's it.