[Python] importlib resources files -> not a package, empty module

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    I tend to alwasy run the testers from inside the module folder, but this breaks the "resources.files" functionality, as it seems not to be able to find the module any more

    module folder

    my_package/
    __init__.py
    package.py
    test_package.py


    package.py

    from importlib import resources
    def run():
    print("running")
    resources.files(__package__)
    return True
    if __name__ == '__main__':
    run()


    test_package.py

    import unittest
    import package
    class TestRest(unittest.TestCase):
    def testSuccess(self):
    self.assertFalse(False)
    def testClassFound(self):
    self.assertIsNotNone(package.run())


    test in module folder:

    $> cd my_package
    my_package $> python -m unittest test_package
    ...
    ValueError: empty module name


    probably because the package attribute in the package.py file is no longer related when inside the module running the test?

    Continue reading...

Compartilhe esta Página