Should Python unittests be in a separate module?

后端 未结 7 2000
攒了一身酷
攒了一身酷 2021-02-12 16:44

Is there a consensus about the best place to put Python unittests?

Should the unittests be included within the same module as the functionality being tested (executed wh

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 17:08

    YES, do use a separate module.

    It does not really make sense to use the __main__ trick. Just assume that you have several files in your module, and it does not work anymore, because you don't want to run each source file separately when testing your module.

    Also, when installing a module, most of the time you don't want to install the tests. Your end-user does not care about tests, only the developers should care.

    No, really. Put your tests in tests/, your doc in doc, and have a Makefile ready around for a make test. Any other approaches are just intermediate solutions, only valid for specific tiny modules.

提交回复
热议问题