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.3.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.3-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_chdir-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 5caf98e54dadc3c7e3d0a629640b731006b856d4ac788e912e670b76c04f3cd0
MD5 f83e26313163cf305d15139781ed0e46
BLAKE2b-256 348dc7f618afd0a65ed60fff7b6f37f6be39d30d69d111193bc3e2d03563c718

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_chdir-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8250d8ace0121fa6c01f6f73533ab7e140142bd7fabd8809f6ed1e5b4b3dd5b
MD5 17ba6718b1c675784eb45dc114ba2d43
BLAKE2b-256 b31c425020eca84ba8432655453b6e5939e14c9c030e76a934240c4e856687ab

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