This is a question about testing environment setup.
In my project, I have a few unit tests that access test data files. These unit tests can be run from my project directory via a test runner. Or I can run each test file/module individually, for debugging purposes, for instance.
The problem is that depending on where I run the tests from, the current directory is different. So opening a test data file, as below, by giving a path relative to the current directory will not work when those files are run from the project directory, as the test data file is not in that directory.
f = open('test_data.ext', 'r')
I thought of using __file__ to use a path relative the current test module, but this doesn't work when the test module calling __file__ is the one being run individually.
How do people generally solve this problem?