def test_issue2369_collect_module_fileext(self, pytester: Pytester) -> None:
        """Ensure we can collect files with weird file extensions as Python
        modules (#2369)"""
        # Implement a little meta path finder to import files containing
        # Python source code whose file extension is ".narf".
        pytester.makeconftest(
            """
            import sys
            import os.path
            from importlib.util import spec_from_loader
            from importlib.machinery import SourceFileLoader
            from _pytest.python import Module

            class MetaPathFinder:
                def find_spec(self, fullname, path, target=None):
                    if os.path.exists(fullname + ".narf"):
                        return spec_from_loader(
                            fullname,
                            SourceFileLoader(fullname, fullname + ".narf"),
                        )
            sys.meta_path.append(MetaPathFinder())

            def pytest_collect_file(file_path, parent):
                if file_path.suffix == ".narf":
                    return Module.from_parent(path=file_path, parent=parent)
            """
        )
        pytester.makefile(
            ".narf",
            """\
            def test_something():
                assert 1 + 1 == 2""",
        )
        # Use runpytest_subprocess, since we're futzing with sys.meta_path.
        result = pytester.runpytest_subprocess()
        result.stdout.fnmatch_lines(["*1 passed*"])
Ensure we can collect files with weird file extensions as Python
        modules (#2369)
testing/python/collect.py