How to use test_sleep method in pytest-benchmark

Best Python code snippet using pytest-benchmark

01-run.py

Source:01-run.py Github

copy

Full Screen

...24 child.sendline('import utime')25 child.expect_exact('>>>')26 # testing timing over serial using the REPL is very inaccurate, thus27 # we allow a *large* overshoot (100 by default).28 def test_sleep(t, slack=100):29 before = get_time()30 child.sendline('utime.sleep_ms(%s)' % t)31 child.expect_exact('>>>')32 duration = get_time() - before33 print("test_sleep(%s, %s): slept %sms" % (t, slack, duration))34 assert duration > t and duration < (t + slack)35 return duration36 # get overhead from sleeping 0ms, add 10 percent37 slack = int(test_sleep(0, 1000) * 1.1)38 test_sleep(50, slack)39 test_sleep(250, slack)40 test_sleep(500, slack)41 # test setting timers42 child.sendline('import xtimer')43 child.expect_exact('>>>')44 child.sendline('a = 0')45 child.expect_exact('>>>')46 child.sendline('def inc_a(): global a; a+=1')47 child.expect_exact('...')48 child.sendline('')49 child.expect_exact('>>>')50 child.sendline('t = xtimer.xtimer(inc_a)')51 child.expect_exact('>>>')52 before = get_time()53 child.sendline('t.set(500000)')54 child.expect_exact('>>>')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful