1

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.

Peter
  • 2,919
  • 1
  • 16
  • 35
  • Are you worried about security or namespace confusion or something else? That is, why not move `test.py` to a subdirectory `foo/test/test.py` following the advice here https://stackoverflow.com/a/24266885/2541138? – PeterK Dec 17 '20 at 14:53

0 Answers0