简体   繁体   中英

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. I can get the each test case execution result using pytest <filename> --durations=0 cmd. But, How to get whole suite execution time>

Use pytest-sugar

pip install pytest-sugar

Run your tests after it,

You could something like Results (10.00s) after finishing the tests

Although this isn't a PyTest solution...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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