Skip to content

Is there a Pytest equivalent to the unittest unittest.TestLoader.loadTestsFromModule() method? #9138

Answered by nicoddemus
SchoofsEbert asked this question in Q&A
Discussion options

You must be logged in to vote

One way I can think of now is to implement your own pytest_pycollect_makemodule hook, which would return a custom Module object. Here's the default implementation that can be used as basis:

def pytest_pycollect_makemodule(fspath: Path, parent) -> "Module":
if fspath.name == "__init__.py":
pkg: Package = Package.from_parent(parent, path=fspath)
return pkg
mod: Module = Module.from_parent(parent, path=fspath)
return mod

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SchoofsEbert
Comment options

Answer selected by SchoofsEbert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants