Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在travis测试中处理相对python路径_Python_Travis Ci - Fatal编程技术网

如何在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