I have a series of tests that inherit from a base class, which looks like this:
class Test(TestCase):
def setUp(self):
module_dir = os.path.dirname(self.__module__.replace('.', '/'))
self.payload_dir = os.path.join(settings.BASE_DIR, module_dir, 'payloads')
This works fine, but self.__module__.replace('.', '/')
isn't very pythonic, and won't work on Windows.
Is there a better way to convert a module name into a relative path?