If test cases are defined in a class that derives from a base class that inherits unitetest.TestCase in a different package only certain kinds of import declarations allow the test methods to be discovered by the Test Adapter and show up in VS2012 Test
Explorer. Basically in the below example depending on how I import BaseC the methods testMethod5 and testMethod6 would not show up in Test Explorer.
Version information: VS2012 SP1, Python 3.2, PTVS 2 RC.
I've attached a small trivial VS2012 solution in a zip file to illustrate my example.
In my example I have 3 different test classes deriving from unittest.TestCase but located in different places and I check to see if they appear in the Test Explorer.
from CustomCase import BaseB
# Three potential ways of importing package, only 1 works for Test Explorer test discovery.
from pkgC.PackageCase import BaseC # This style shows all cases in Test Explorer
#from pkgC import BaseC # This style doesn't show cases in Test Explorer
#from pkgC import * # This style doesn't show cases in Test Explorer
# Wrap the unittest case class locally in this file as BaseA
# Derive from local wrapper.
self.foo() # call BaseA method
# Derive from wrapper BaseB which is in the same package.
self.bar() # call BaseB method
# Derive from wrapper BaseC which is in another (nested) package
self.packageMethod() # call BaseC method
# Run all test cases
if __name__ == '__main__':
The real world example of this is a base test case class located in a common package that would get imported and inherited from in other modules for test cases to be written inside. If the import approach isn't correct we don't see visibility of the test case
in Test Explorer even though we can run all our test cases just fine.