Hi guys, I have a question regarding using paths i...
# general
l
Hi guys, I have a question regarding using paths in tests I have this structure
Copy code
library
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
Copy code
# 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 that
b
What you have is fine for that, I think. Another option would be
importlib.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.
l
Thanks @broad-processor-92400!