I have many tests for a class with a C extension. I redo the same tests for:
- the c implementation
- the pure py implementation
- the subclass of the c implementation
- the subclass of the py implementation
Since not all tests are common for the 4 cases, I created 4 files:
common.py file filled with
To call the same tests for the different classes, I
common.py. This is an example with test.py
import pytest import pippo as pippo_module from pippo.purepy import pippo as pippo_class from pathlib import Path c_ext = False curr_path = Path(__file__) curr_dir = curr_path.parent with open(curr_dir / "common.py") as f: common_code = f.read() exec(common_code) with open(curr_dir / "pippo_only.py") as f: pippo_only_code = f.read() exec(pippo_only_code)
pippo_only.py contains tests for only the pure py implementation.
It works, but I feel it really hacky. Do you know if there’s a more simple and elegant way to achive this?