mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 14:57:09 +01:00
feat: consider the workdir in pytest annotations
This commit is contained in:
parent
7442569c25
commit
0d3dd791da
3 changed files with 40 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ import {
|
|||
TestCaseResult,
|
||||
TestCaseError
|
||||
} from '../../test-results'
|
||||
import {getBasePath, normalizeFilePath} from '../../utils/path-utils'
|
||||
|
||||
export class PytestJunitParser implements TestParser {
|
||||
assumedWorkDir: string | undefined
|
||||
|
|
@ -102,7 +103,7 @@ export class PytestJunitParser implements TestParser {
|
|||
|
||||
if (path && Number.isFinite(line)) {
|
||||
return {
|
||||
path,
|
||||
path: this.getRelativePath(path),
|
||||
line,
|
||||
message: lines[1]
|
||||
}
|
||||
|
|
@ -110,4 +111,21 @@ export class PytestJunitParser implements TestParser {
|
|||
|
||||
return undefined
|
||||
}
|
||||
|
||||
private getRelativePath(path: string): string {
|
||||
path = normalizeFilePath(path)
|
||||
const workDir = this.getWorkDir(path)
|
||||
if (workDir !== undefined && path.startsWith(workDir)) {
|
||||
path = path.substring(workDir.length + 1)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
private getWorkDir(path: string): string | undefined {
|
||||
return (
|
||||
this.options.workDir ??
|
||||
this.assumedWorkDir ??
|
||||
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue