8000 unittest.TestLoader.loadTestsFrom* module arguments should have module type, not str · Issue #2008 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content
unittest.TestLoader.loadTestsFrom* module arguments should have module type, not str #2008
Closed
@russ-

Description

@russ-

Several methods on unittest.TestLoader have a "module" argument. Inspecting the code, its clear that these functions actually operate on modules directly. I believe they've incorrectly been typed str.

From https://github.com/python/typeshed/blob/master/stdlib/2/unittest.pyi#L195:

class TestLoader:
...
    def loadTestsFromModule(self, module: str = ...,
                            use_load_tests: bool = ...) -> TestSuite: ...
    def loadTestsFromName(self, name: str = ...,
                          module: Optional[str] = ...) -> TestSuite: ...
    def loadTestsFromNames(self, names: List[str] = ...,
                          module: Optional[str] = ...) -> TestSuite: ...

From https://github.com/python/cpython/blob/master/Lib/unittest/loader.py#L121:

    def loadTestsFromModule(self, module, *args, pattern=None, **kws):
        ...
        for name in dir(module):
            obj = getattr(module, name)
            if isinstance(obj, type) and issubclass(obj, case.TestCase):
                tests.append(self.loadTestsFromTestCase(obj))
        ...

Clearly, for name in dir(module) is not going to yield unittest.TestCase subclasses if module is a str; the code expects a module object instead. The same is true for loadTestsFromName and loadTestsFromNames.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0