更好的python单元测试集成?

2024-09-27 17:42:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用GNU Emacs 24.5.1处理Python代码。我通常只想运行一个单元测试。我可以这样做,例如,通过运行:

test=spi.test_views.IndexViewTest.generate_select2_data_with_embedded_spaces  make test

使用M-X编译。如果我能给出一些命令,比如“在点所在的位置运行测试”,并让emacs为我计算出测试的全名,我的生活会更简单。有可能吗

更新:使用以下缓冲区,我想要一些运行M-X compile的命令:

test=spi.test_views.IndexViewTest.test_unknown_button make test

其中spi是test_views.py所在目录的名称。从技术上讲,我需要构造测试函数的python路径,但在实践中,它将是<;directory.file.class.function>

这似乎是有人已经发明的东西,但我在python模式文档中没有看到任何东西

enter image description here


Tags: 代码testgnu命令spidatamakewith
1条回答
网友
1楼 · 发布于 2024-09-27 17:42:14

我相信您使用的是“default”python模式,而所谓的^{} mode(我强烈建议在Emacs中进行Python开发时尝试一下)似乎提供了您想要的:

 C-c C-t (elpy-test)

Start a test run. This uses the currently configured test runner to discover
and run tests. If point is inside a test case, the test runner will run exactly
that test case. Otherwise, or if a prefix argument is given, it will run all tests.

额外细节

elpy-test函数在内部依赖于函数(elpy-test-at-point),这似乎非常接近您在问题中提到的功能

请参见以下屏幕截图中的代码/帮助摘录:

elpy-test

相关问题 更多 >

    热门问题