Note that there are some explanatory texts on larger screens.

plurals
  1. POImportError cannot import name when using baseclass with multiple subclasses
    primarykey
    data
    text
    <p>I need to have a base class that runs setup/teardown, then subclasses that inherit, in order to allow for all tests to run regardless if certain ones fail. When attempting to have multiple subclasses that import a base class, I see an import error for the second subclass. I have the following files: <code>runtestcases.py</code> <code>testcase1.py</code> <code>testcase2.py</code></p> <p>Here is runtestcases.py:</p> <pre><code>import unittest import testcase1, testcase2 class ArithTestSuper (unittest.TestCase): def setUp (self): print("Setting up ArithTest cases") def tearDown (self): print("Cleaning up ArithTest cases") def my_suite(): suite = unittest.TestSuite() suite.addTest (testcase1.ArithTest()) suite.addTest (testcase2.ArithTestFail()) return suite if __name__ == '__main__': runner = unittest.TextTestRunner() test_suite = my_suite() runner.run (test_suite) </code></pre> <p>Here is testcase1.py:</p> <pre><code>from runtestcases import ArithTestSuper class ArithTest (ArithTestSuper): def runTest (self): """ Test addition and succeed. """ print("Running ArithTest") self.failUnless (1+1==2, 'one plus one fails!') self.failIf (1+1 != 2, 'one plus one fails again!') self.failUnlessEqual (1+1, 2, 'more trouble with one plus one!') </code></pre> <p>Here is testcase2.py:</p> <pre><code>from runtestcases import ArithTestSuper class ArithTestFail (ArithTestSuper): def runTest (self): """ Test addition and fail. """ print("Running ArithTestFail") self.failUnless (1+1==2, 'one plus one fails!') self.failIf (1+1 != 2, 'one plus one fails again!') self.failUnlessEqual (1+1, 2, 'more trouble with one plus one!') self.failIfEqual (1+1, 2, 'expected failure here') self.failIfEqual (1+1, 2, 'second failure') Compilation fails on testcase2.py with: ImportError: cannot import name ArithTestSuper </code></pre> <p>If I run just testcase1 it works - likewise, running just testcase2 works. If I try both this error occurs. Thoughts?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload