ar90n / pytest-chdir

A pytest fixture for changing current working directory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pytest-chdir

A pytest fixture for changing current working directory.

Actions Status PyPI PythonVersions

Usage

Change directory to tmpdir

Using chtmpdir provides not only creating temporary directory but also moving there automatically.

def test_move_to_tmpdir(chtmpdir):
    assert Path.cwd() == chtmpdir
    assert str(chtmpdir).startswith("/tmp")

Define new fixtures to change current working directory

By using define_chdir_fixture, you can create a fixture to move to specified directory.

define_chdir_fixture("chetc", Path("/etc"), __name__)

def test_chetc(chetc):
    assert Path.cwd() == Path("/etc")

Integrate with pytest-datadir

If you have installed pytest-datadir, you can use chdatadir and chshared_datadir.

def test_chdatadir(chdatadir):
    assert str(Path.cwd().stem) == "test_dir"

def test_chshared_datadir(chshared_datadir):
    assert str(Path.cwd().stem) == "data"

See also

License

This software is released under the MIT License, see LICENSE.

About

A pytest fixture for changing current working directory

License:MIT License


Languages

Language:Python 100.0%