Relative imports with unittest in Python

前端 未结 3 1547
忘了有多久
忘了有多久 2020-12-30 19:32

I am trying to use Python unittest and relative imports, and I can\'t seem to figure it out. I know there are a lot of related questions, but none of them have helped so fa

3条回答
  •  不知归路
    2020-12-30 20:05

    In a layout where tests and package are at sibling level:

    /project
       /tests
       /package
    

    One way is to start within the package dir, use -s to discover only in tests, and use -t to set the top level:

    ../package $ python3 -m unittest discover -s ../tests -t ..
    
    

提交回复
热议问题