File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 55
66from __future__ import annotations
77
8+ import re
89import textwrap
10+ from unittest import mock
911
1012import pytest
1113
1214from coverage import env
13- from coverage .exceptions import NotPython
15+ from coverage .exceptions import NoSource , NotPython
1416from coverage .parser import PythonParser
1517
1618from tests .coveragetest import CoverageTest
@@ -1147,3 +1149,10 @@ def test_missing_line_ending(self) -> None:
11471149
11481150 parser = self .parse_file ("abrupt.py" )
11491151 assert parser .statements == {1 }
1152+
1153+ def test_os_error (self ) -> None :
1154+ self .make_file ("cant-read.py" , "BOOM!" )
1155+ msg = "No source for code: 'cant-read.py': Fake!"
1156+ with pytest .raises (NoSource , match = re .escape (msg )):
1157+ with mock .patch ("coverage.python.read_python_source" , side_effect = OSError ("Fake!" )):
1158+ PythonParser (filename = "cant-read.py" )
You can’t perform that action at this time.
0 commit comments