Skip to main content

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_chdir-0.2.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_chdir-0.2.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_chdir-0.2.1.tar.gz.

File metadata

  • Download URL: pytest_chdir-0.2.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-35-generic

File hashes

Hashes for pytest_chdir-0.2.1.tar.gz
Algorithm Hash digest
SHA256 08cdd00b124d57474eb28c0f88a108ad99d8d9f1e2ba1de0603e701f141fe586
MD5 0557612c7b4835f7fd48e0e2c0ede768
BLAKE2b-256 f72002421414423fe8cc54c60cb37ca1e6b7aaf36154c0a59b8dfeb789635192

See more details on using hashes here.

File details

Details for the file pytest_chdir-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_chdir-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-35-generic

File hashes

Hashes for pytest_chdir-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 023d64d6fc67404c1adf2ebae056745bab793dd97af95a24b78293f80c02fd3b
MD5 78f8540ddee21e8d8b39736150f09472
BLAKE2b-256 089385b9b77c4109027695c9aa59322800ad580f7a168c4953fea3317d5e9d01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page