[英]How to find time take by whole test suite to complete in Pytest
I want to know how much time has been taken by the whole test suite to complete the execution.我想知道整个测试套件花了多少时间来完成执行。 How can I get it in Pytest framework.
如何在 Pytest 框架中获取它。 I can get the each test case execution result using
pytest <filename> --durations=0
cmd.我可以使用
pytest <filename> --durations=0
cmd 获取每个测试用例的执行结果。 But, How to get whole suite execution time>但是,如何获得整个套件的执行时间>
Use pytest-sugar
使用
pytest-sugar
pip install pytest-sugar
Run your tests after it,在它之后运行你的测试,
You could something like Results (10.00s)
after finishing the tests完成测试后,您可能会出现类似
Results (10.00s)
的内容
Although this isn't a PyTest
solution...虽然这不是
PyTest
解决方案......
You can probably make your own timer!您可能可以制作自己的计时器! Here's one I made a little while ago:
这是我不久前制作的一个:
from time import time as t
class Timer:
def __init__(self) : self.tstart, self.tend = None, None
def start(self) : self.tstart = t()
def end(self) : self.tend = t()
def getDis(self) : return self.tend - self.tstart
You can use it like this:你可以这样使用它:
n = Timer()
n.start()
# something you want to do
n.end()
print (n.getDis()) # gets the distance between the start and finish
It can print out 0.00
when measuring something really fast, like a few import
statements, though.但是,当测量非常快的东西时,它可以打印出
0.00
,比如一些import
语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.