0

I have a "models" folder, inside which i have different models that are used for unit testing. File hierarchy is as follows

- test
  - models
    - nn_class.sav
    - nn_reg.sav
  - test_model

I run test_model, which has unit test inside. And when i read the file nn_class.sav, it works perfectly fine by giving path "./models". Whereas when i try to run the same tests on Github, it throws the error of File not found. I have to use this instead, so it can find files in both environments.

model_name = 'nn_class.sav'
    if os.path.isdir('./models'):
        path = './models/'
    else:
        path = 'test/models/'

Is there a nice elegant way to deal with this issue. Someone suggested fixtures to me, i don't know if they'll be helpful.

Saif Ali Khan
  • 25
  • 1
  • 7

1 Answers1

0

Not a neat way and better to avoid such tricks, but try to do

import sys
sys.path.insert(0, '.') 

in the beginning of your test_model file, it will use root as run path for the case. then you can use relative path to the root. Or whatever folder, just change . to the path you need.

See comments to the reply here why it is better to avoid such tricks: https://stackoverflow.com/a/448279/2957102

Sysanin
  • 1,501
  • 20
  • 27