简体   繁体   English

Py.Test 获取剩余的测试用例数

[英]Py.Test getting remaining test case count

Is there a way to get the test cases that are yet to be executed with Py.Test (in a py.test setup fixture with function scope or in pytest_exception_interact) .有没有办法获取尚未使用 Py.Test 执行的测试用例(在具有函数作用域的 py.test 设置装置中或在 pytest_exception_interact 中)。

When a test case is failed, I am setting a global flag in my conftest to indicate the test failure and reset the application to a default state in pytest_exception_interact and in the function setup of next function ,I validate this flag to run a set of pre-conditions before executing the tests.当测试用例失败时,我在我的 conftest 中设置一个全局标志来指示测试失败并将应用程序重置为 pytest_exception_interact 和下一个函数的函数设置中的默认状态,我验证此标志以运行一组预- 执行测试之前的条件。 Now , I do not want to run the actions i am peforming when the last test case fails.现在,我不想在最后一个测试用例失败时运行我正在执行的操作。

I was able to get the information of total tests in a module with the argument node (node.parent._collected ), but I could not find a way to check if the tests are already executed or not .我能够使用参数节点 (node.parent._collected) 在模块中获取总测试的信息,但我找不到检查测试是否已经执行的方法。 Right now , all I am doing is check the index of current test in this list and see how many are still in the queue to be executed .现在,我所做的就是检查此列表中当前测试的索引,看看还有多少仍在等待执行的队列中。

def pytest_exception_interact(node, call, report):
    pass

If anybody, has a better solution kindly let me know.如果有人有更好的解决方案,请告诉我。

"pytest_exception_interact" is only called when exceptions are raised. “pytest_exception_interact”仅在引发异常时调用。

You can use use:您可以使用:

def pytest_collection_finish(session):
    total_tests_number = len(session.items)

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

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