Reputation: 5020
Here is my test script:
# tests/runner.py
import unittest
# import your test modules
import TC110
import TC112
# initialize the test suite
loader = unittest.TestLoader()
suite = unittest.TestSuite()
# add tests to the test suite
suite.addTests(loader.loadTestsFromModule(TC110))
suite.addTests(loader.loadTestsFromModule(TC112))
# initialize a runner, pass it your suite and run it
runner = unittest.TextTestRunner(verbosity=3)
result = runner.run(suite)
I have TC110.py and TC112.py in the same directory and am running my test like this,
"python -m unittest runner"
I am getting output like this,
test_ldap_login (TC110.TestTC110) ... ok
test_download_artifact (TC112.TestTC112) ... ok
----------------------------------------------------------------------
Ran 2 tests in 1.929s
OK
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Why I am getting "Ran 0 tests", how to get rid of this?
Upvotes: 0
Views: 940
Reputation: 281748
You're getting an extra "Ran 0 tests" for essentially the same reason that print(print("asdf"))
prints an extra None
: you're issuing two testing commands.
Your runner.py
script loads tests from other files and runs them. If you had simply told Python to run the script (python runner.py
), you wouldn't have gotten the spurious extra output.
Instead of telling Python to run the script, you have told the unittest module to load and run all tests from runner.py
. As a side effect, this runs the body of runner.py
, running the tests you wanted. unittest
then loads and runs all 0 tests contained in runner.py
, because you told it to.
Upvotes: 2