パンダを使用して相対パスから CSV ファイルを読み取ることを含むコードの単体テストを作成しようとしています。ディレクトリ構造は次のとおりです。
./
./thing1/main.py
./thing1/test_main.py
./thing1/dat/file.csv
./otherthings/...
でmain.py
、私は持っています:
def doThings:
pandas.read_csv('dat/file.csv')
if __name__ == '__main__':
doThings()
でtest_main.py
、私は持っています
class TestMain:
def setup(self):
doThings()
def test_thing(self):
pass # there's other logic in here
を実行すると問題なく動作しますmain.py
が、Anaconda に「プロジェクト テストを実行する」ように依頼すると、「dat/file.csv」が存在しないという不平を言う IOError が発生します。に変更すると機能するため、相対パスであるという事実に関連してい/home/user/.../thing1/dat/file.csv
ます。相対パスを維持しながら単体テストを機能させる方法はありますか?