def _build_config_for_path(path): """ Builds and returns a basic test configuration rooted at the given path. Args: path (LocalPath): The path to the files under test. Returns: Config: The generated test configuration. """ # Find the root directory of the package containing our files. for rootdir in path.parts(reverse=True): if rootdir.join("setup.py").exists(): break else: rootdir = path # Initialize a base configuration as pytest would. pluginmanager = PytestPluginManager() for spec in default_plugins: pluginmanager.import_plugin(spec) config = Config(pluginmanager) # Ensure that pytest sets its root directory (``config.rootdir``) to the # given path. If we don't, then using this configuration from outside of # this path will confuse pytest. args = [rootdir] config.parse(args) return config
def test_prepared_config(terminal_writer_mock: mock.MagicMock) -> Config: config = Config(PytestPluginManager()) test_pytest_parser = Parser( usage="%(prog)s [options] [file_or_dir] [file_or_dir] [...]", processopt=config._processopt ) pytest_addoption(test_pytest_parser) config._parser = test_pytest_parser return config
def test_empty_config() -> Config: return Config(PytestPluginManager())