File: test_time.py

package info (click to toggle)
python-pytest-shell-utilities 1.9.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: python: 2,998; makefile: 18
file content (18 lines) | stat: -rw-r--r-- 494 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Copyright 2022-2024 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
#
import time
from unittest import mock

import pytestshellutils.utils.time


def test_sleep() -> None:
    start = time.time()
    with mock.patch("time.sleep", return_value=None):
        time.sleep(1)
        pytestshellutils.utils.time.sleep(0.1)
    end = time.time()
    duration = end - start
    assert duration >= 0.1  # We did sleep 0.1 second
    assert duration < 0.5  # But the patched time.sleep was mocked