Skip to content

Commit 2e30808

Browse files
committed
Split test with if for windows vs other
1 parent c54c9ea commit 2e30808

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/test_cmd2.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,8 +1795,15 @@ def test_commandresult_falsy(commandresult_app):
17951795

17961796
def test_is_text_file_bad_input(base_app):
17971797
# Test with a non-existent file - on GitHub Actions Windows test runners, we get a PermissionError
1798-
with pytest.raises((FileNotFoundError, PermissionError)):
1799-
utils.is_text_file('does_not_exist.txt')
1798+
file_name = 'does_not_exist.txt'
1799+
if sys.platform.startswith('win'):
1800+
# For Windows, depending on setup you might get a FileNotFoundError or a PermissionError
1801+
with pytest.raises(OSError): # noqa: PT011
1802+
utils.is_text_file(file_name)
1803+
else:
1804+
# For Linux or macOS you should reliably get a FileNotFoundError
1805+
with pytest.raises(FileNotFoundError):
1806+
utils.is_text_file(file_name)
18001807

18011808
# Test with a directory
18021809
with pytest.raises(IsADirectoryError):

0 commit comments

Comments
 (0)