Relative imports with unittest in Python

前端 未结 3 1549
忘了有多久
忘了有多久 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 19:57

    I run with the same problem and kai's answer solved it. I just want to complement his answer with the content of test.py (as @gsanta asked). I've only tested it on Python 2.7:

    from packages.tests import test_a, test_b
    import unittest
    
    # for test_a
    unittest.main(test_a, exit=False)
    
    # for test_b
    unittest.main(test_b)
    

    then you can just

    ../project $ python test.py
    

提交回复
热议问题