Skip to content

Commit b40e3b8

Browse files
committed
Chore: Fix tests on Windows
1 parent 3085550 commit b40e3b8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/test_core_infra.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# (c) 2018-2023 The mqttwarn developers
33
import configparser
4-
import re
54
import socket
65
import sys
76
import threading
@@ -717,19 +716,22 @@ def test_load_services_spec_not_found(caplog):
717716
assert ex.match("1")
718717

719718

720-
def test_load_services_file_not_found(caplog):
719+
def test_load_services_file_not_found(tmp_path, caplog):
721720
"""
722721
Loading a service where its module can not be discovered from a file name path, should fail.
723722
"""
723+
724+
modulefile = tmp_path / "foo_bar.py"
725+
724726
config = Config()
725-
config.configuration_path = "/tmp"
727+
config.configuration_path = tmp_path
726728
config.add_section("config:foo.bar")
727729
config.set("config:foo.bar", "module", "foo_bar.py")
728730
bootstrap(config=config)
729731
with pytest.raises(SystemExit) as ex:
730732
load_services(["foo.bar"])
731733
assert 'Module "foo_bar.py" is not a file' in caplog.messages
732-
assert 'Module "/tmp/foo_bar.py" is not a file' in caplog.messages
734+
assert f'Module "{modulefile}" is not a file' in caplog.messages
733735
assert 'Unable to load service "foo.bar"' in caplog.messages
734736
assert ex.match("1")
735737

@@ -751,7 +753,7 @@ def test_load_services_file_failure(tmp_path, caplog):
751753

752754
with pytest.raises(SystemExit) as ex:
753755
load_services(["foo.bar"])
754-
assert re.match(r'.*Loading service "foo.bar" from file ".+/foo_bar.py" failed.*', caplog.text, re.DOTALL)
756+
assert f'Loading service "foo.bar" from file "{modulefile}" failed' in caplog.text
755757
assert "AssertionError" in caplog.text
756758
assert 'Unable to load service "foo.bar"' in caplog.messages
757759
assert ex.match("1")

0 commit comments

Comments
 (0)