1616package io .qameta .allure .scalatest
1717
1818import java .lang .annotation .Annotation
19- import java .util .UUID
19+ import java .util .{ Objects , UUID }
2020import java .util .concurrent .TimeUnit
2121import java .util .concurrent .locks .ReentrantReadWriteLock
2222
@@ -162,7 +162,7 @@ class AllureScalatest(val lifecycle: AllureLifecycle) extends Reporter {
162162 event.suiteClassName,
163163 event.location,
164164 event.testName,
165- None
165+ Some (event.threadName)
166166 )
167167 stopTest(
168168 None ,
@@ -180,7 +180,7 @@ class AllureScalatest(val lifecycle: AllureLifecycle) extends Reporter {
180180 val uuid = UUID .randomUUID().toString
181181 var labels = mutable.ListBuffer (
182182 createSuiteLabel(suiteName),
183- createThreadLabel( ),
183+ createLabel( THREAD_LABEL_NAME , getScalaTestThreadName(threadId) ),
184184 createHostLabel(),
185185 createLanguageLabel(" scala" ),
186186 createFrameworkLabel(" scalatest" )
@@ -227,15 +227,21 @@ class AllureScalatest(val lifecycle: AllureLifecycle) extends Reporter {
227227 private def stopTest (status : Option [Status ],
228228 statusDetails : Option [StatusDetails ],
229229 threadName : Option [String ]): Unit = {
230- threadName.fold {} { thread => AllureScalatestContextHolder .remove(thread) }
231- lifecycle.getCurrentTestCase.ifPresent(uuid => {
232- lifecycle.updateTestCase(uuid, (result : TestResult ) => {
233- status.fold {} { st => result.setStatus(st) }
234- statusDetails.fold {} { details => result.setStatusDetails(details) }
235- }: Unit )
236- lifecycle.stopTestCase(uuid)
237- lifecycle.writeTestCase(uuid)
238- })
230+ threadName.fold {} {
231+ thread => {
232+ AllureScalatestContextHolder .get(thread).fold {} {
233+ uuid => {
234+ lifecycle.updateTestCase(uuid, (result : TestResult ) => {
235+ status.fold {} { st => result.setStatus(st) }
236+ statusDetails.fold {} { details => result.setStatusDetails(details) }
237+ }: Unit )
238+ lifecycle.stopTestCase(uuid)
239+ lifecycle.writeTestCase(uuid)
240+ }
241+ AllureScalatestContextHolder .remove(thread)
242+ }
243+ }
244+ }
239245 }
240246
241247 private def getAnnotations (location : Option [Location ]): List [Annotation ] = location match {
@@ -273,4 +279,11 @@ class AllureScalatest(val lifecycle: AllureLifecycle) extends Reporter {
273279 }
274280 }
275281
282+ private def getScalaTestThreadName (threadId : Option [String ]): String = {
283+ val fromProperty = System .getProperty(ALLURE_THREAD_NAME_SYSPROP )
284+ val fromEnv = System .getenv(ALLURE_THREAD_NAME_ENV )
285+ val realThreadName = threadId.getOrElse {getThreadName}
286+ Seq (fromProperty, fromEnv).find(el => Objects .nonNull(el)).getOrElse {realThreadName}
287+ }
288+
276289}
0 commit comments