Background
I have a class which performs fairly slow, complex operations on data. I want to write some tests for that class, but I'm having a hard time finding a suitable testing framework.
The class has an interface like this:
class thing():
def __init__(self, datafile):
data = read datafile
def a(self):
self.data_a = expensive(self.data)
def b(self):
self.data_b = expensive(self.data_a)
def c(self):
self.data_c = expensive(self.data_b)
etc...
The way we use this class is we usually sequentially perform the operations and analyze the results, usually at each step, often in a jupyter notebook.
Question
How should one test the methods in a class which have this structure? Is there a framework / convention for building sequential test suites?
I tried...
I tried using pytest, like so:
@pytest.mark.incremental class Test_thing(object): def setUp(self): generated_data = generate(data) generated_data.write(somewhere) self.t = thing(somewhere) def test_a(self): self.t.a() assert self.t.data_a hasProperties def test_b(self): self.t.b() assert self.t.data_b hasProperties
But
test_b
would fail withdata_a is not an attribute of thing
which is a feature, not a bug, of pytest: the tests operate in isolation from one another. But I want the opposite.I also tried unittest some time ago, but couldn't find a way to phrase my tests in that framework.
At present, I've written the tests without a testing framework, basically the pytest code from above, without pytest references, and at the end:
t = Test_thing() t.setUp() t.test_a() t.test_b() ...
Is that the best I can do?
Notes
I'm also looking for recommendations on a better title for this question