I have a class for testing some of my code. I would like to parametrize the setup and rerun the class with different parameters:
class TestNormalLTEPlasma:
def setup(self, t=10000):
self.plasma = plasma.LTEPlasma.from_abundance(t, {'Si':1.0}, 1e-13, atom_data, 10*86400)
def test_beta_rad(self):
assert self.plasma.beta_rad == 1 / (10000 * constants.k_B.cgs.value)
def test_t_electron(self):
assert self.plasma.t_electron == 0.9 * self.plasma.t_rad
def test_saha_calculation_method(self):
assert self.plasma.calculate_saha == self.plasma.calculate_saha_lte
I would like to run this class going from t=2000 to t=20000 in steps of 1000
Instead of your setup function, create a parametrized test fixture:
A "parametrized test fixture" is one where, when you use it in a test case, pytest will create a new test case for each parameter and run each separately.
You use the test fixture by adding a function argument called "plasma" to each of the test functions that want it:
pytest takes care of collecting fixtures, collecting test functions, figuring out which test functions need which fixtures, and passing the fixture values to the test functions for execution.
Check out the docs for more details: http://pytest.org/latest/fixture.html#fixture-parametrize