pycharm - Python 蛋疼的单元测试, 有什么好的目录结构?
高洛峰
高洛峰 2017-04-18 09:52:58
0
2
487

平常主要是依靠 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 单测方法,能让目录结构更加清晰

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
Peter_Zhu

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

大家讲道理

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)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!