Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dev = [
"pymdown-extensions>=10.21.3,<11.0.0",
"pytest>=9.0.3,<10.0.0",
"pytest-cov>=7.0.0,<8.0.0",
"pytest-freezegun==0.4.2", # Unmaintained; strict pin required for stability
"time-machine>=2.14.0", # Replaces unmaintained pytest-freezegun
"pytest-it>=0.1.5,<0.2.0",
"pytest-mock>=3.14.0,<4.0.0",
"requests-mock>=1.12,<2.0.0",
Expand Down
11 changes: 8 additions & 3 deletions tests/unit/test_reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pathlib

from freezegun.api import FakeDatetime
from datetime import datetime

import time_machine
from pytest import fixture, mark

from scanapi.reporter import Reporter
Expand Down Expand Up @@ -57,7 +59,6 @@ def test_init_output_path_and_template_3(self):

@mark.describe("reporter")
@mark.describe("write")
@mark.freeze_time("2020-05-12 11:32:34")
class TestWrite:
@fixture
def mocked__render(self, mocker):
Expand All @@ -78,7 +79,7 @@ def mocked__webbrowser(self, mocker):
@fixture
def context(self, mocked__session):
return {
"now": FakeDatetime(2020, 5, 12, 11, 32, 34),
"now": datetime(2020, 5, 12, 11, 32, 34),
"project_name": "",
"results": fake_results,
"session": mocked__session,
Expand All @@ -92,6 +93,7 @@ def mocked__open(self, mocker):
return mock

@mark.it("should write to default output")
@time_machine.travel("2020-05-12 11:32:34")
def test_should_write_to_default_output(
self,
mocked__render,
Expand All @@ -111,6 +113,7 @@ def test_should_write_to_default_output(
mocked__open().write.assert_called_once_with("ScanAPI Report")

@mark.it("should write to custom output")
@time_machine.travel("2020-05-12 11:32:34")
def test_should_write_to_custom_output(
self,
mocked__render,
Expand All @@ -130,6 +133,7 @@ def test_should_write_to_custom_output(
mocked__open().write.assert_called_once_with("ScanAPI Report")

@mark.it("should handle custom templates")
@time_machine.travel("2020-05-12 11:32:34")
def test_should_handle_custom_templates(
self,
mocked__render,
Expand All @@ -151,6 +155,7 @@ def test_should_handle_custom_templates(
mocked__open().write.assert_called_once_with("ScanAPI Report")

@mark.it("should open report in browser")
@time_machine.travel("2020-05-12 11:32:34")
def test_should_open_report_in_browser(
self,
mocked__render,
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test_session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from random import randrange

import time_machine
from pytest import mark, raises

from scanapi.session import Session
Expand Down Expand Up @@ -36,7 +37,7 @@ def test_failed_when_there_is_failure(self, failures, errors, expected):
@mark.describe("start")
class TestStart:
@mark.it("should initialize started_at with current time")
@mark.freeze_time("2020-06-15 18:54:57")
@time_machine.travel("2020-06-15 18:54:57")
def test_init_started_at(self):
session = Session()

Expand Down Expand Up @@ -108,10 +109,10 @@ def test_increment(self):
@mark.describe("elapsed_time")
class TestElapsedTime:
@mark.it("should return time")
@mark.freeze_time("2020-06-15 18:54:57")
def test_return_time(self, freezer):
@time_machine.travel("2020-06-15 18:54:57")
def test_return_time(self, time_machine):
session = Session()

freezer.move_to("2020-06-15 18:56:38")
time_machine.move_to("2020-06-15 18:56:38")

assert str(session.elapsed_time()) == "0:01:41"
Loading