def METHOD_NAME(tmp_path, monkeypatch):
    monkeypatch.chdir(str(tmp_path))
    (tmp_path / 'pkg' / 'foo').mkdir(parents=True)
    (tmp_path / 'pkg' / '__init__.py').write_text(
        'from pkgutil import extend_path\n'
        '__path__ = extend_path(__path__, __name__)\n')
    (tmp_path / 'pkg' / 'foo' / '__init__.py').write_text('')
    (tmp_path / 'pkg' / 'foo' / 'bar.py').write_text('')
    with patch.dict(sys.modules):
        for modname in list(sys.modules):
            if modname == 'pkg' or modname.startswith('pkg.'):
                del sys.modules[modname]
        with pytest.raises(ImportError):
            find_module('pkg.missing')
        with pytest.raises(ImportError):
            find_module('pkg.foo.missing')
        assert find_module('pkg.foo.bar')
        with pytest.raises(NotAPackage) as exc_info:
            find_module('pkg.foo.bar.missing')
        assert exc_info.value.args[0] == 'pkg.foo.bar'