From fcebd63e668ba6ba039b7a9eb87b2b58c618af27 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Tue, 3 Dec 2019 23:52:14 +0100 Subject: [PATCH] Speed up tests by mocking time.sleep() --- tests/conftest.py | 17 +++++++++++++++++ tests/test_dosage.py | 1 + tests/test_modules.py | 2 ++ 3 files changed, 20 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..41ff88e7b --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019 Tobias Gruetzmacher + +from __future__ import absolute_import, division, print_function + +import time + +import pytest + + +@pytest.fixture +def nosleep(monkeypatch): + + def sleep(seconds): + pass + + monkeypatch.setattr(time, 'sleep', sleep) diff --git a/tests/test_dosage.py b/tests/test_dosage.py index 3896701f2..814a87592 100644 --- a/tests/test_dosage.py +++ b/tests/test_dosage.py @@ -28,6 +28,7 @@ def cmd_err(*options): assert cmd(*options) == 1 +@pytest.mark.usefixtures("nosleep") class TestDosage(object): """Test the dosage commandline client.""" diff --git a/tests/test_modules.py b/tests/test_modules.py index bbf8325af..4cadf8ed7 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function import re +import pytest import responses import dosagelib.cmd @@ -16,6 +17,7 @@ def cmd(*options): assert dosagelib.cmd.main(("--allow-multiple",) + options) == 0 +@pytest.mark.usefixtures("nosleep") class TestModules(object): """Test that specific comic modules work correctly."""