First differing element 1:
(‘sta[191 chars]exp_prefix’, (‘exp_inv_ind’, (‘exp_base’, (‘VA[411 chars]’))))
(‘sta[191 chars]exp_pdbn’, (‘exp_pow’, (‘exp_inv_elems’, (‘exp[424 chars]’))))
Diff is 1390 characters long. Set self.maxDiff to None to see it.
Ran 2 tests in 0.210s
FAILED (failures=1)
Each tests builds a parser for a tiny toy language using parser_gen.py…in one case for a C like language. In another for a Pythonic language. The beginning of each unit test makes the parser and a related function called p_and_tok. Can I define different versions in different unit tests?
At a glance, your cache decorator doesn’t consider whether parser_ changed, so you likely have bad cache sharing between calls with different parser_s.
In any such case, one test is changing something somewhere. Unittest recognizes a setUp method (check the manual) to properly initialize the ‘something’. Or add a tearDown method, or do it in the methods.
Yes thank you. I love setUp and tearDown. They avoid having
to copy boilerplate to every unit test. Reloading the relevant modules
in setUp gave every unit test cleaned state and solved all.
Thanks so much. I can’t believe how fast this forum caught this one.
I thought it would take a long time.
Interesting. I’ve also heard of nose in addition to pytest. The only reason I can see to ever sticking with unittest is because it’s in the standard library.
nose is no longer developed - it’s last release is almost 10 years old.
pytest is the de-facto standard for unit tests in python. Basically all major packages use that. It’s much more capable and convenient compared to the standard library’s unittest. Unless you have very strong resticitions to not have any additional dev dependencies, go with pytest.