简体   繁体   中英

How to handle relative python paths in travis test

I have a unittest that loads json file with simulate(config="../data/config/default.json") and locally it runs fine and tests are passed.

Then I pass it to .travis.yml with - python -m unittest tests.test_consistency and it cannot find this json file. It raises error:

FileNotFoundError: [Errno 2] No such file or directory: '../data/config/default.json'

why is that, am I missing something with relative paths?

It seems that this solution worked, so whatever local file I have file.json I changed it in the test files to:

CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'file.json')

It makes the code harder to work with, though. I needed to overload all places where I load the files locally with

params.paths.G = os.path.join(root_path,  params.paths.G)  # graphml of a current .city

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM