pytest-nodeid-to-filepath
Get a filepath based on the current Pytest node ID.
The node ID of the current test is read from the environment variable PYTEST_CURRENT_TEST and transformed to a string which can be used safely as filename on any OS.
Optionally the directory argument can be given to resolve the path against this directory. The directory needs to be relative to Pytest root.
Installation
uv add pytest-nodeid-to-filepath
Usage
from pytest_nodeid_to_filepath import get_filepath
def test_basic():
path = get_filepath(extension=".txt")
assert path.name == "test_main.py--test_basic.txt"
assert path.parent.name == "tests"
Filenames are unique if tests are parametrized. Parameter are be part of the filename as plain text or as hash.
import pytest
from pytest_nodeid_to_filepath import get_filepath
class Mydataclass:
foo: str = "bar"
@pytest.mark.parametrize("number_as_string", ("one", "two"))
@pytest.mark.parametrize("number_as_int", (1, 2))
@pytest.mark.parametrize("my_object", (Mydataclass(), Mydataclass()))
def test_use_params_instead_of_hash(
number_as_string: str,
number_as_int: int,
my_object: Mydataclass,
):
path = get_filepath()
assert path.name in (
"test_main.py--test_use_params_instead_of_hash[my_object0-1-one]",
"test_main.py--test_use_params_instead_of_hash[my_object1-2-two]",
"test_main.py--test_use_params_instead_of_hash[my_object0-2-one]",
"test_main.py--test_use_params_instead_of_hash[my_object1-1-two]",
"test_main.py--test_use_params_instead_of_hash[my_object0-2-two]",
"test_main.py--test_use_params_instead_of_hash[my_object1-1-one]",
"test_main.py--test_use_params_instead_of_hash[my_object0-1-two]",
"test_main.py--test_use_params_instead_of_hash[my_object1-2-one]",
)
assert path.parent.name == "tests"
More usage examples can be fount in tests/test_main.py.
Metadata
Release files for pytest-nodeid-to-filepath 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_nodeid_to_filepath-0.1.0.tar.gz | 18.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_nodeid_to_filepath-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.3 kB
Release files / pytest_nodeid_to_filepath-0.1.0.tar.gz
| Download URL | pytest_nodeid_to_filepath-0.1.0.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cf93a9f8a008e2eee05869d281bed3b4cc879651d0a245f474360d6a6c00e08
|
|
BLAKE2b-256 checksum How to use checksums |
314168d344a6a8eb96de86c8699a189b7eb734d69a4f63630a493c61b8956907
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pytest_nodeid_to_filepath-0.1.0-py3-none-any.whl
| Download URL | pytest_nodeid_to_filepath-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3ce7f4d8b6a1deae3b88b43a0db984d69cd913759076c599868e4eb2b65dc22
|
|
BLAKE2b-256 checksum How to use checksums |
a31ab4ae4c2fab790636c98e2e904557e44f899503d2ee070f985bf69f724fbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|