Home  >  Q&A  >  body text

pycharm - Python 蛋疼的单元测试, 有什么好的目录结构?

平常主要是依靠 Python(PyCharm) + Java(Intellij)做开发

对于某一个用户自定义的方法都可以通过 Navigate->Test 来创建单测

用 Intellij 的 Maven 框架的话,创建单元测试非常舒服,自动会在对应的 test 目录下面建立相应的文件

例如
src/main/java/abc/run.java
对应的测试文件是
test/java/abc/runTest.java

但是 Pycharm 就蛋疼了,同样自动创建单元测试,其目录结构直接就是在相同目录下创建
例如在 src 目录下
src/abc/run.py
自动创建的文件位置
src/abc/test_run.py

巨丑,

目前我是手动集中到一个新建的 test 目录下,尽量模仿 Maven 格式,但总觉的路子有点野

不知道有木有 Python 大神,知道正规 or 人性化 的 Python 单测方法,能让目录结构更加清晰

高洛峰高洛峰2764 days ago527

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 09:54:58

    v2ex, posted a question, everyone will probably discuss the answer and connect

    Create a tests in the root directory

    Then name it according to the format of test_UNIT.py. If the amount of code is large, create some sub-folders according to the functions to classify them. That’s it.

    You can refer to the source code of requests and django

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:54:58

    requests is a relatively standard layout, and its author also explained that placing tests that way is beneficial

    I think it’s better to refer to standardized open source projects (the layout of tests in some projects is extremely random)

    reply
    0
  • Cancelreply