3 ms·
Python scope still freaks me out. It's weird to me that the "candidate" referenced by FoundationEngineerTestCase is the same candidate instantiated at the bott
by jimbokun 16y ago
Python scope still freaks me out.
It's weird to me that the "candidate" referenced by FoundationEngineerTestCase is the same candidate instantiated at the bottom of the file, without ever being explicitly passed into an instance of that class. I would have expected:
test_program = CandidateTestProgram(candidate)
Furthermore, how is CandidateTestProgram connected to FoundationEngineerTestCase? Does it do a global search for subclasses of unittest.TestCase, then instantiate and execute them?
- digitallogic 16y agoReferencing the 'candidate' variable from within the test case is not a good approach as it's referencing a module global instead of an attribute. Additionally, it only exists when the module is executed directly, so if it's imported and run in a different manner a name error will result for every test that references. As for the TestProgram, it's inheriting routines from the base class in the unittest module that do introspection to find all test fixtures.