feat: consider the workdir in pytest annotations

This commit is contained in:
Martin Fillafer 2023-03-14 11:30:29 +01:00
parent 7442569c25
commit 0d3dd791da
3 changed files with 40 additions and 3 deletions

View file

@ -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))
)
}
}