fixtures#

Collection of pytest fixtures used in conda tests.

Classes#

Functions#

suppress_resource_warning()

Suppress Unclosed Socket Warning

tmpdir(tmpdir, request)

clear_subdir_cache()

disable_channel_notices()

Fixture that will set "context.number_channel_notices" to 0 and then set

reset_conda_context()

Resets the context object after each test function is run.

temp_package_cache(tmp_path_factory)

Used to isolate package or index cache from other tests.

parametrized_solver_fixture(...)

A parameterized fixture that sets the solver backend to (1) libmamba

solver_classic(...)

solver_libmamba(...)

_solver_helper(→ collections.abc.Iterable[Solver])

session_capsys(...)

conda_cli(→ collections.abc.Iterator[CondaCLIFixture])

A function scoped fixture returning CondaCLIFixture instance.

session_conda_cli(...)

A session scoped fixture returning CondaCLIFixture instance.

path_factory(...)

A function scoped fixture returning PathFactoryFixture instance.

tmp_env(→ collections.abc.Iterator[TmpEnvFixture])

A function scoped fixture returning TmpEnvFixture instance.

session_tmp_env(→ collections.abc.Iterator[TmpEnvFixture])

A session scoped fixture returning TmpEnvFixture instance.

tmp_channel(→ collections.abc.Iterator[TmpChannelFixture])

A function scoped fixture returning TmpChannelFixture instance.

context_aware_monkeypatch(→ pytest.MonkeyPatch)

A monkeypatch fixture that resets context after each test.

tmp_pkgs_dir(→ collections.abc.Iterator[pathlib.Path])

A function scoped fixture returning a temporary package cache directory.

tmp_envs_dir(→ collections.abc.Iterator[pathlib.Path])

A function scoped fixture returning a temporary environment directory.

Attributes#

suppress_resource_warning()#

Suppress Unclosed Socket Warning

It seems urllib3 keeps a socket open to avoid costly recreation costs.

xref: kennethreitz/requests#1882

tmpdir(tmpdir, request)#
clear_subdir_cache()#
disable_channel_notices()#

Fixture that will set "context.number_channel_notices" to 0 and then set it back to its original value.

This is also a good example of how to override values in the context object.

reset_conda_context()#

Resets the context object after each test function is run.

temp_package_cache(tmp_path_factory)#

Used to isolate package or index cache from other tests.

parametrized_solver_fixture(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch) collections.abc.Iterable[Literal[libmamba, classic]]#

A parameterized fixture that sets the solver backend to (1) libmamba and (2) classic for each test. It's using autouse=True, so only import it in modules that actually need it.

Note that skips and xfails need to be done _inside_ the test body. Decorators can't be used because they are evaluated before the fixture has done its work!

So, instead of:

@pytest.mark.skipif(context.solver == "libmamba", reason="...") def test_foo():

...

Do:

def test_foo():
if context.solver == "libmamba":

pytest.skip("...")

...

solver_classic(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch) collections.abc.Iterable[Literal[classic]]#
solver_libmamba(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch) collections.abc.Iterable[Literal[libmamba]]#
Solver#
_solver_helper(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch, solver: Solver) collections.abc.Iterable[Solver]#
session_capsys(request) collections.abc.Iterator[_pytest.capture.MultiCapture]#
class CondaCLIFixture#
capsys: pytest.CaptureFixture | _pytest.capture.MultiCapture#
__call__(*argv: str | os.PathLike | pathlib.Path, raises: type[Exception] | tuple[type[Exception], Ellipsis]) tuple[str, str, pytest.ExceptionInfo]#
__call__(*argv: str | os.PathLike | pathlib.Path) tuple[str, str, int]

Test conda CLI. Mimic what is done in conda.cli.main.main.

conda ... == conda_cli(...)

Parameters:
  • argv -- Arguments to parse.

  • raises -- Expected exception to intercept. If provided, the raised exception will be returned instead of exit code (see pytest.raises and pytest.ExceptionInfo).

Returns:

Command results (stdout, stderr, exit code or pytest.ExceptionInfo).

conda_cli(capsys: pytest.CaptureFixture) collections.abc.Iterator[CondaCLIFixture]#

A function scoped fixture returning CondaCLIFixture instance.

Use this for any commands that are local to the current test (e.g., creating a conda environment only used in the test).

session_conda_cli(session_capsys: _pytest.capture.MultiCapture) collections.abc.Iterator[CondaCLIFixture]#

A session scoped fixture returning CondaCLIFixture instance.

Use this for any commands that are global to the test session (e.g., creating a conda environment shared across tests, conda info, etc.).

class PathFactoryFixture#
tmp_path: pathlib.Path#
__call__(name: str | None = None, prefix: str | None = None, suffix: str | None = None) pathlib.Path#

Unique, non-existent path factory.

Extends pytest's tmp_path fixture with a new unique, non-existent path for usage in cases where we need a temporary path that doesn't exist yet.

Parameters:
  • name -- Path name to append to tmp_path

  • prefix -- Prefix to prepend to unique name generated

  • suffix -- Suffix to append to unique name generated

Returns:

A new unique path

path_factory(tmp_path: pathlib.Path) collections.abc.Iterator[PathFactoryFixture]#

A function scoped fixture returning PathFactoryFixture instance.

Use this to generate any number of temporary paths for the test that are unique and do not exist yet.

class TmpEnvFixture#
path_factory: PathFactoryFixture | pytest.TempPathFactory#
conda_cli: CondaCLIFixture#
get_path() pathlib.Path#
__call__(*packages: str, prefix: str | os.PathLike | None = None) collections.abc.Iterator[pathlib.Path]#

Generate a conda environment with the provided packages.

Parameters:
  • packages -- The packages to install into environment

  • prefix -- The prefix at which to install the conda environment

Returns:

The conda environment's prefix

tmp_env(path_factory: PathFactoryFixture, conda_cli: CondaCLIFixture) collections.abc.Iterator[TmpEnvFixture]#

A function scoped fixture returning TmpEnvFixture instance.

Use this when creating a conda environment that is local to the current test.

session_tmp_env(tmp_path_factory: pytest.TempPathFactory, session_conda_cli: CondaCLIFixture) collections.abc.Iterator[TmpEnvFixture]#

A session scoped fixture returning TmpEnvFixture instance.

Use this when creating a conda environment that is shared across tests.

class TmpChannelFixture#
path_factory: PathFactoryFixture#
conda_cli: CondaCLIFixture#
__call__(*packages: str) collections.abc.Iterator[tuple[pathlib.Path, str]]#
tmp_channel(path_factory: PathFactoryFixture, conda_cli: CondaCLIFixture) collections.abc.Iterator[TmpChannelFixture]#

A function scoped fixture returning TmpChannelFixture instance.

context_aware_monkeypatch(monkeypatch: pytest.MonkeyPatch) pytest.MonkeyPatch#

A monkeypatch fixture that resets context after each test.

tmp_pkgs_dir(path_factory: PathFactoryFixture, mocker: pytest_mock.MockerFixture) collections.abc.Iterator[pathlib.Path]#

A function scoped fixture returning a temporary package cache directory.

tmp_envs_dir(path_factory: PathFactoryFixture, mocker: pytest_mock.MockerFixture) collections.abc.Iterator[pathlib.Path]#

A function scoped fixture returning a temporary environment directory.