[Python] Using resource files in python (pytest) tests

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    Could someone tell me what the correct way of dealing with resource files in pytest?

    I have a habit of creating a resources directory just under the package (src) directory and another under the test branch

    root---package---resource_dir
    | |-file1.py
    | |-file2.py
    |
    |-test-- resource_dir-
    | |-config1.csv
    | |-config2.csv
    |-test1.py
    |-test2.py


    If I want to access these files from within my tests what is the pythonic way of doing so? Up to now I have been using relative file paths but that solution isn't great. Is there a solution similar to the Java resources solution?

    Continue reading...

Compartilhe esta Página