11# -*- coding: utf-8 -*-
22# (c) 2018-2023 The mqttwarn developers
33import configparser
4- import re
54import socket
65import sys
76import 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