@@ -188,6 +188,9 @@ func junitXMLTestReport(suite *moduletest.Suite, suiteRunnerStopped bool, source
188188 },
189189 })
190190
191+ // Check if there are file-level errors that will be reported at suite level
192+ hasFileLevelErrors := file .Status == moduletest .Error && file .Diagnostics .HasErrors ()
193+
191194 for i , run := range file .Runs {
192195 // Each run is a "test case".
193196
@@ -209,7 +212,7 @@ func junitXMLTestReport(suite *moduletest.Suite, suiteRunnerStopped bool, source
209212 // Depending on run status, add either of: "skipped", "failure", or "error" elements
210213 switch run .Status {
211214 case moduletest .Skip :
212- testCase .Skipped = skipDetails (i , file , suiteRunnerStopped )
215+ testCase .Skipped = skipDetails (i , file , suiteRunnerStopped , hasFileLevelErrors )
213216
214217 case moduletest .Fail :
215218 // When the test fails we only use error diags that originate from failing assertions
@@ -275,6 +278,16 @@ func junitXMLTestReport(suite *moduletest.Suite, suiteRunnerStopped bool, source
275278 })
276279 }
277280
281+ // Add suite-level system-err if there are file-level errors
282+ if hasFileLevelErrors {
283+ systemErr := & withMessage {
284+ Body : getDiagString (file .Diagnostics , sources ),
285+ }
286+ enc .EncodeElement (systemErr , xml.StartElement {
287+ Name : xml.Name {Local : "system-err" },
288+ })
289+ }
290+
278291 enc .EncodeToken (xml.EndElement {Name : suiteName })
279292 }
280293 enc .EncodeToken (xml.EndElement {Name : suitesName })
@@ -300,8 +313,9 @@ func failureMessage(failedAssertions tfdiags.Diagnostics, checkCount int) string
300313// Test can be skipped due to:
301314// 1. terraform test recieving an interrupt from users; all unstarted tests will be skipped
302315// 2. A previous run in a file has failed, causing subsequent run blocks to be skipped
316+ // 3. File-level errors (e.g., invalid variable references) causing all tests to be skipped
303317// The returned value is used to set content in the "skipped" element
304- func skipDetails (runIndex int , file * moduletest.File , suiteStopped bool ) * withMessage {
318+ func skipDetails (runIndex int , file * moduletest.File , suiteStopped bool , hasFileLevelErrors bool ) * withMessage {
305319 if suiteStopped {
306320 // Test suite experienced an interrupt
307321 // This block only handles graceful Stop interrupts, as Cancel interrupts will prevent a JUnit file being produced at all
@@ -323,6 +337,14 @@ func skipDetails(runIndex int, file *moduletest.File, suiteStopped bool) *withMe
323337 }
324338 }
325339 }
340+
341+ // Check for file-level error diagnostics that caused tests to be skipped
342+ // Note: Full diagnostic details are included in suite-level <system-err> element
343+ if hasFileLevelErrors {
344+ return & withMessage {
345+ Message : "Testcase skipped due to file-level errors" ,
346+ }
347+ }
326348 }
327349
328350 // Unhandled case: This results in <skipped></skipped> with no attributes or body
0 commit comments