little-afternoon-68046
04/24/2024, 10:06 AMlibrary
tests
test_features
test_feature_a.py
BUILD
resources
BUILD
input_data.json
What would be the best way for creating a path inside test_feature_a.py
To read tests/test_features/resources/input_data.json
I was thinking of using abs path
# test_feature_a.py
from pathlib import Path
script_dir = Path(__file__).parent
json_path = script_dir/ 'resources' / 'input_data.json'
with open(json_path, 'r') as f:
pass
This works ok, however I'm not sure if thats the safest solution, I couldn't find any good practice domumented for something like thatbroad-processor-92400
04/24/2024, 11:36 AMimportlib.resources in the stdlib.
There’s some cases (eg “zipapp”) where an application might not be running from a real file system (so `open`wont work) and that stdlib module handles those better… but this is unlikely to be relevant for running tests.little-afternoon-68046
04/24/2024, 11:40 AM