@@ -142,6 +142,61 @@ def test_report_including(self) -> None:
142142        assert  "mycode.py "  in  report 
143143        assert  self .last_line_squeezed (report ) ==  "TOTAL 4 0 100%" 
144144
145+     def  test_report_include_relative_files_and_path (self ) ->  None :
146+         """ 
147+         Test that when relative_files is True and a relative path to a module 
148+         is included, coverage is reported for the module. 
149+ 
150+         Ref: https://github.com/nedbat/coveragepy/issues/1604 
151+         """ 
152+         self .make_mycode ()
153+         config  =  """ 
154+         [run] 
155+         relative_files = true 
156+         """ 
157+         self .make_file (".coveragerc" , config )
158+         self .make_file ("submodule/mycode.py" , "import mycode" )
159+ 
160+         cov  =  coverage .Coverage ()
161+         self .start_import_stop (cov , "submodule/mycode" )
162+         report  =  self .get_report (cov , include = "submodule/mycode.py" )
163+ 
164+         # Name                Stmts   Miss  Cover 
165+         # --------------------------------------- 
166+         # submodule/mycode.py 1       0     100% 
167+         # --------------------------------------- 
168+         # TOTAL               1       0     100% 
169+ 
170+         assert  "submodule/mycode.py "  in  report 
171+         assert  self .last_line_squeezed (report ) ==  "TOTAL 1 0 100%" 
172+ 
173+     def  test_report_include_relative_files_and_wildcard_path (self ) ->  None :
174+         self .make_mycode ()
175+         config  =  """ 
176+         [run] 
177+         relative_files = true 
178+         """ 
179+         self .make_file (".coveragerc" , config )
180+         self .make_file ("submodule/mycode.py" , "import nested.submodule.mycode" )
181+         self .make_file ("nested/submodule/mycode.py" , "import mycode" )
182+ 
183+         cov  =  coverage .Coverage ()
184+         self .start_import_stop (cov , "submodule/mycode" )
185+         report  =  self .get_report (cov , include = "*/submodule/mycode.py" )
186+ 
187+         # Name                          Stmts   Miss  Cover 
188+         # ------------------------------------------------- 
189+         # nested/submodule/mycode.py    1       0     100% 
190+         # submodule/mycode.py           1       0     100% 
191+         # ------------------------------------------------- 
192+         # TOTAL                         2       0     100% 
193+ 
194+         reported_files  =  [line .split ()[0 ] for  line  in  report .splitlines ()[2 :4 ]]
195+         assert  reported_files  ==  [
196+             "nested/submodule/mycode.py" ,
197+             "submodule/mycode.py" ,
198+         ]
199+ 
145200    def  test_omit_files_here (self ) ->  None :
146201        # https://github.com/nedbat/coveragepy/issues/1407 
147202        self .make_file ("foo.py" , "" )
0 commit comments