Created
September 21, 2023 20:32
-
-
Save L3viathan/241f092983524f8b94190fa2666e351d to your computer and use it in GitHub Desktop.
Tiny pytest plugin that allows collecting any file regardless of extension. If you don't manually specify test files, this will probably crash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from importlib.util import spec_from_loader, module_from_spec | |
from importlib.machinery import SourceFileLoader | |
import pytest | |
class ModuleWithoutExtension(pytest.Module): | |
def _importtestmodule(self): | |
print(self.path, type(self.path)) | |
spec = spec_from_loader(self.path.name, SourceFileLoader(self.path.name, str(self.path))) | |
mod = module_from_spec(spec) | |
spec.loader.exec_module(mod) | |
self.config.pluginmanager.consider_module(mod) | |
return mod | |
def pytest_collect_file(file_path, path, parent): | |
return ModuleWithoutExtension.from_parent(parent, path=file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment