How to use py.test from Python?

前端 未结 7 871
旧巷少年郎
旧巷少年郎 2020-12-30 04:38

I\'m working in a project that recently switched to the py.test unittest framework. I was used to call my tests from Eclipse, so that I can use the debugger (e.g. placing br

7条回答
  •  离开以前
    2020-12-30 05:10

    I think I can now answer my own question, it's pretty simple:

    import py
    py.test.cmdline.main(args)
    

    Then I can run this module and or start it with the integrated debugger.

    args is the list of command line arguments, so for example to run only particular tests I can use something like:

    args_str = "-k test_myfavorite"
    py.test.cmdline.main(args_str.split(" "))
    

提交回复
热议问题