如何在travis测试中处理相对python路径
我有一个如何在travis测试中处理相对python路径,python,travis-ci,Python,Travis Ci,我有一个unittest,它用simulate(config=“../data/config/default.json”)加载json文件,并且在本地运行良好,测试通过 然后我用-python-m unittest tests.test\u consistency将它传递给.travis.yml,它找不到这个json文件。这会引起错误: FileNotFoundError: [Errno 2] No such file or directory: '../data/config/default.
unittest
,它用simulate(config=“../data/config/default.json”)
加载json
文件,并且在本地运行良好,测试通过
然后我用-python-m unittest tests.test\u consistency
将它传递给.travis.yml
,它找不到这个json
文件。这会引起错误:
FileNotFoundError: [Errno 2] No such file or directory: '../data/config/default.json'
为什么,我缺少一些相对路径?似乎解决方案有效,所以无论我有什么本地文件file.json
我都在测试文件中将其更改为:
CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'file.json')
但是,这使得代码更难使用。我需要重载本地加载文件的所有位置
params.paths.G = os.path.join(root_path, params.paths.G) # graphml of a current .city