This fails:
def test_main_imports_pathlib():
print(f'"pathlib" in sys.modules {"pathlib" in sys.modules}') # prints "True"
if 'pathlib' in sys.modules:
del sys.modules['pathlib']
import core.__main__
assert 'pathlib' in sys.modules
but __main__.py looks like this:
import pathlib
NB things are set up with conventional "src" and "tests" top directories and, yes, __main__.py definitely gets imported in the above test.
Is there a way to test whether an application file imports a module using pytest? I'm open to the idea that this might be dismissed an an "implementation detail" and that I should be testing for something bigger. But in fact I think that this is a trivial example of something you might well be justified in checking: what imports what...
In fact I'd like to understand why the above fails.