I am converting a Python project test package from unittest to nose. The existing project structure (based on unittest) is pretty awkward, with lots of highly customizable codes for detecting and running tests, so I'm trying to move my nose to make things more streamlined.
However, I ran into problems with code creating test packages.
The project structure has two ways to run tests. One of them -
class TestSomething(unittest.TestCase): def setUp(self): ... def test_x(self): ... def test_y(self): ... suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestSomething))
which is the “easy” way, this is what all Nose examples and tutorials show, and it works. However, the second way is to define a test class that contains all the test logic, and then create test cases in various subclasses that contain different configurations of settings and inherit tests from the superclass:
class TestSomething(unittest.TestCase): def test_x(self): ... def test_y(self): ... class TestCase1(TestSomething): def setUp(self): ... class TestCase2(TestSomething): def setUp(self): ... suite = unittest.TestSuite() cases = [TestCase1,TestCase2] suite.addTests([unittest.makeSuite(case) for case in cases])
This is what Nose fails. First, he tries to run the testing methods, which obviously does not work, because the superclass does not have setUp (), and many of the variables used in test_x () and test_y () are not yet defined.
I have not found examples that can be done anywhere, and the Nose documentation (quite rare and difficult to navigate) does not seem to mention this either. How can this be done to work with the nose? Any help would be greatly appreciated.
source share