Get a filepath based on the current Pytest node ID.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_nodeid_to_filepath-0.1.0.tar.gz.
File metadata
- Download URL: pytest_nodeid_to_filepath-0.1.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cf93a9f8a008e2eee05869d281bed3b4cc879651d0a245f474360d6a6c00e08
|
|
| MD5 |
dbde4cecc1bf27e8384fb39dda307747
|
|
| BLAKE2b-256 |
314168d344a6a8eb96de86c8699a189b7eb734d69a4f63630a493c61b8956907
|
File details
Details for the file pytest_nodeid_to_filepath-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_nodeid_to_filepath-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3ce7f4d8b6a1deae3b88b43a0db984d69cd913759076c599868e4eb2b65dc22
|
|
| MD5 |
c071156dccdf2ab9852eb17e35d7f257
|
|
| BLAKE2b-256 |
a31ab4ae4c2fab790636c98e2e904557e44f899503d2ee070f985bf69f724fbd
|