I have a Python module foo
with the following layout:
foo
├── __init__.py
└── test.py
test.py
contains a number of test, i.e.:
import unittest
class FooTest(unittest.TestCase):
# ...
if __name__ == '__main__':
unittest.main()
Now, I'd like to be able to run these tests either by running test.py
or by calling a function foo.test
. To make the latter possible I added the following to __init__.py
:
import unittest
from .test import *
def test():
unittest.main()
This works but it pollutes foo
with the tests defined in test.py
. How can I avoid this? I.e. I don't want someone using foo
to be able to see/use foo.FooTest
.