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.2.tar.gz (2.6 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.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_chdir-0.2.2.tar.gz
  • Upload date:
  • Size: 2.6 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.2.tar.gz
Algorithm Hash digest
SHA256 961a506edf1dfaf39951193217b79167743c9432817fd34f82674630039c8264
MD5 9f21b15516049d61bc1c797242b8d08b
BLAKE2b-256 157929f83b6e81d0ae631e9291213de3a85845b0f716baa2e17832483ab2f97d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_chdir-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d2ed292bab84b0d4b47056439a9eccfff06ff3cebc714e277fecdef6243e1003
MD5 24ffc5234914ce5b8c195b894d411ec7
BLAKE2b-256 fd5321d9dd6ffd4fa2136ebb8ba1083ac50be7c7fb95fbf2fec387f32808e90a

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