简体   繁体   English

Nosetest:在执行之前添加装饰器以进行测试

[英]Nosetest: add decorator for tests before execution

I use nosetests and allure framework for reporting purposes. 我使用鼻子测试和诱惑力框架进行报告。 In order to make the report look like I want, I have to add @nose.allure.feature('some feature') decorator to each test. 为了使报告看起来像我想要的,我必须在每个测试中添加@nose.allure.feature('some feature')装饰器。 The problem is that I have over 1000 test. 问题是我有1000多个测试。 Is there any way to modify tests before execution? 有什么方法可以在执行前修改测试?

I was thinking about custom nose plugin, but not sure how can it be implemented. 我在考虑自定义的鼻子插件,但不确定如何实现。

A plug-in is definitely the way to go. 插件绝对是必经之路。 there is a bunch of documentation on creating plug-ins: 关于创建插件有很多文档:

http://nose.readthedocs.io/en/latest/doc_tests/test_issue119/empty_plugin.html http://nose.readthedocs.io/en/latest/search.html?q=+plugin http://nose.readthedocs.io/en/latest/doc_tests/test_issue119/empty_plugin.html http://nose.readthedocs.io/en/latest/search.html?q=+plugin

I think you'll probably want to extend the test runner. 我认为您可能想扩展测试跑步者。 You can look at what that decorator is doing before and after calling the function, and then just add that stuff in the test runner. 您可以查看装饰器在调用函数之前和之后的操作,然后将其添加到测试运行器中。

How about adding the decorator to the test classes instead? 如何将装饰器添加到测试类中呢?

Not sure if it will work, but sometimes works nicely for @patch . 不知道它是否会工作,但有时对于@patch也能很好地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM