I'm working on a small Python package, and I'm writing unit tests for it. I have my package structure laid out in fairly typical Python fashion:
mypackage/
mymodule.py
test/
test_mymodule.py
This particular module is designed to read the contents of a file, do a thing with said contents, and then return a value. In order to test this, I want to include some input files in my test suite.
I suppose I could organize them like this:
mypackage/
mymodule.py
test/
test_mymodule.py
test_input01.txt
test_input02.txt
And then locate the files to read using the __file__
global variable.
My question is: is this a reasonably Pythonic way of organizing things? I'm concerned that guessing paths in this manner won't be reliable in any environment (e.g., if the package is installed via pip or etc.).
Specifically, I'm looking for either 1) some official documentation that supports this (or some other) approach, or 2) a well-regarded existing project that uses this (or some other) approach.