[英]How to handle relative python paths in travis test
我有一个unittest
加载json
与文件simulate(config="../data/config/default.json")
并在本地运行良好,并测试通过。
然后我用- python -m unittest tests.test_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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.