Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
def test_empty_config() -> Config:
    return Config(PytestPluginManager())