Here is what the current test code looks like:
def do_simulation(speed):
df = run_simulation(speed)
# following is a lot of assert that checks the values in df
assert df["X"].iloc[0] == 0
assert df["Y"].iloc[-1] == 2
assert ...
....
def test_simulation():
do_simulation(100)
do_simulation(200)
I want to convert the test code to a Test class:
class TestSimulation(object):
def setup_class(cls):
cls.df = run_simulation(100) # I want to change the speed parameter
def test_1():
"comment 1"
assert self.df["X"].iloc[0] == 0
def test_2():
"comment 2"
assert self.df["Y"].iloc[-1] == 2
I read the document of py.test, but I can't figure out how to run TestSimulation for speed in [100, 200, ...].
the setup_class() method can only have cls argument.
What I want is a Test class that:
- call
do_simulation()once, and store the result. - call all the test method to check the simulation result.
- I can different parameters to
do_simulation().