i tried:
def buildTestSuite():
suite = unittest.TestSuite()
for testcase in glob.glob('src/testsuite/test_*.py'):
module = os.path.splitext(testcase)[0]
print module
print type(module)
suite.addTest(__import__(module).buildTestSuite())
return suite
but i get eror:
Traceback (most recent call last):
File "runtests.py", line 63, in ?
results = main()
File "runtests.py", line 57, in main
results = unittest.TextTestRunner().run(buildTestSuite())
File "runtests.py", line 53, in buildTestSuite
suite.addTest(__import__(module).buildTestSuite())
AttributeError: 'module' object has no attribute 'buildTestSuite'
The following steps are involved in creating and running a test suite. Step 1 − Create an instance of TestSuite class. Step 2 − Add tests inside a TestCase class in the suite. Step 4 − Individual tests can also be added in the suite.
setUp allows us to write preparation code that is run for all of our tests in a TestCase subclass. Note: If you have multiple test files with TestCase subclasses that you'd like to run, consider using python -m unittest discover to run more than one test file.
To get started, select a method, a type, or a namespace in the code editor in the project you want to test, right-click, and then choose Create Unit Tests. The Create Unit Tests dialog opens where you can configure how you want the tests to be created.
A test suite is a collection of test cases, test suites, or both. It is used to aggregate tests that should be executed together. test runner. A test runner is a component which orchestrates the execution of tests and provides the outcome to the user.
def buildTestSuite():
suite = unittest.TestSuite()
for testcase in glob.glob('src/testsuite/test_*.py'):
modname = os.path.splitext(testcase)[0]
module=__import__(modname,{},{},['1'])
suite.addTest(unittest.TestLoader().loadTestsFromModule(module))
return suite
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With