diff --git a/__tests__/__outputs__/python-xunit.md b/__tests__/__outputs__/python-xunit.md index 5715276..230d186 100644 --- a/__tests__/__outputs__/python-xunit.md +++ b/__tests__/__outputs__/python-xunit.md @@ -1,17 +1,23 @@ -![Tests failed](https://img.shields.io/badge/tests-2%20passed%2C%201%20failed-critical) +![Tests failed](https://img.shields.io/badge/tests-4%20passed%2C%202%20failed%2C%202%20skipped-critical) |Report|Passed|Failed|Skipped|Time| |:---|---:|---:|---:|---:| -|[fixtures/python-xunit.xml](#user-content-r0)|2 ✅|1 ❌||220ms| -## ❌ fixtures/python-xunit.xml -**3** tests were completed in **220ms** with **2** passed, **1** failed and **0** skipped. +|[fixtures/python-xunit-unittest.xml](#user-content-r0)|4 ✅|2 ❌|2 ⚪|1ms| +## ❌ fixtures/python-xunit-unittest.xml +**8** tests were completed in **1ms** with **4** passed, **2** failed and **2** skipped. |Test suite|Passed|Failed|Skipped|Time| |:---|---:|---:|---:|---:| -|[pytest](#user-content-r0s0)|2 ✅|1 ❌||220ms| -### ❌ pytest +|[TestAcme-20251114214921](#user-content-r0s0)|4 ✅|2 ❌|2 ⚪|1ms| +### ❌ TestAcme-20251114214921 ``` -src.acme.test_lib +TestAcme ✅ test_always_pass - ✅ test_always_skip + ✅ test_parameterized_0_param1 + ✅ test_parameterized_1_param2 + ✅ test_with_subtests ❌ test_always_fail - failed + AssertionError: failed + ❌ test_error + Exception: error + ⚪ test_always_skip + ⚪ test_expected_failure ``` \ No newline at end of file diff --git a/__tests__/__snapshots__/python-xunit.test.ts.snap b/__tests__/__snapshots__/python-xunit.test.ts.snap index 94a1046..555d41f 100644 --- a/__tests__/__snapshots__/python-xunit.test.ts.snap +++ b/__tests__/__snapshots__/python-xunit.test.ts.snap @@ -1,44 +1,87 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`python-xunit tests report from python test results matches snapshot 1`] = ` +exports[`python-xunit unittest report report from python test results matches snapshot 1`] = ` TestRunResult { - "path": "fixtures/python-xunit.xml", + "path": "fixtures/python-xunit-unittest.xml", "suites": [ TestSuiteResult { "groups": [ TestGroupResult { - "name": "src.acme.test_lib", + "name": "TestAcme", "tests": [ TestCaseResult { "error": undefined, "name": "test_always_pass", "result": "success", - "time": 36.386333, + "time": 0, }, TestCaseResult { "error": undefined, - "name": "test_always_skip", + "name": "test_parameterized_0_param1", "result": "success", - "time": 92.039167, + "time": 1, + }, + TestCaseResult { + "error": undefined, + "name": "test_parameterized_1_param2", + "result": "success", + "time": 0, + }, + TestCaseResult { + "error": undefined, + "name": "test_with_subtests", + "result": "success", + "time": 0, }, TestCaseResult { "error": { - "details": undefined, + "details": "Traceback (most recent call last): + File "/Users/foo/Projects/python-test/tests/test_lib.py", line 24, in test_always_fail + self.fail("failed") +AssertionError: failed +", "line": undefined, - "message": "failed", + "message": "AssertionError: failed", "path": undefined, }, "name": "test_always_fail", "result": "failed", - "time": 92.05175, + "time": 0, + }, + TestCaseResult { + "error": { + "details": "Traceback (most recent call last): + File "/Users/foo/Projects/python-test/tests/test_lib.py", line 31, in test_error + raise Exception("error") +Exception: error +", + "line": undefined, + "message": "Exception: error", + "path": undefined, + }, + "name": "test_error", + "result": "failed", + "time": 0, + }, + TestCaseResult { + "error": undefined, + "name": "test_always_skip", + "result": "skipped", + "time": 0, + }, + TestCaseResult { + "error": undefined, + "name": "test_expected_failure", + "result": "skipped", + "time": 0, }, ], }, ], - "name": "pytest", - "totalTime": 220.47725000000003, + "name": "TestAcme-20251114214921", + "totalTime": 1, }, ], - "totalTime": undefined, + "totalTime": 1, } `; diff --git a/__tests__/fixtures/python-xunit-unittest.xml b/__tests__/fixtures/python-xunit-unittest.xml new file mode 100644 index 0000000..ecc67d4 --- /dev/null +++ b/__tests__/fixtures/python-xunit-unittest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + diff --git a/__tests__/fixtures/python-xunit.xml b/__tests__/fixtures/python-xunit.xml deleted file mode 100644 index c2872f7..0000000 --- a/__tests__/fixtures/python-xunit.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/__tests__/python-xunit.test.ts b/__tests__/python-xunit.test.ts index e4adeab..9959ce0 100644 --- a/__tests__/python-xunit.test.ts +++ b/__tests__/python-xunit.test.ts @@ -6,16 +6,21 @@ import {ParseOptions} from '../src/test-parser' import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' import {normalizeFilePath} from '../src/utils/path-utils' -describe('python-xunit tests', () => { - it('report from python test results matches snapshot', async () => { - const fixturePath = path.join(__dirname, 'fixtures', 'python-xunit.xml') - const outputPath = path.join(__dirname, '__outputs__', 'python-xunit.md') - const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) - const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) +const defaultOpts: ParseOptions = { + parseErrors: true, + trackedFiles: [] +} - const trackedFiles = ['src/acme/test_lib.py'] +describe('python-xunit unittest report', () => { + const fixturePath = path.join(__dirname, 'fixtures', 'python-xunit-unittest.xml') + const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) + const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) + + it('report from python test results matches snapshot', async () => { + const outputPath = path.join(__dirname, '__outputs__', 'python-xunit.md') + const trackedFiles = ['tests/test_lib.py'] const opts: ParseOptions = { - parseErrors: true, + ...defaultOpts, trackedFiles } @@ -29,16 +34,7 @@ describe('python-xunit tests', () => { }) it('report does not include a title by default', async () => { - const fixturePath = path.join(__dirname, 'fixtures', 'python-xunit.xml') - const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) - const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) - - const opts: ParseOptions = { - parseErrors: true, - trackedFiles: [] - } - - const parser = new PythonXunitParser(opts) + const parser = new PythonXunitParser(defaultOpts) const result = await parser.parse(filePath, fileContent) const report = getReport([result]) // Report should have the badge as the first line @@ -51,16 +47,7 @@ describe('python-xunit tests', () => { ['tab', '\t'], ['newline', '\n'] ])('report does not include a title when configured value is %s', async (_, reportTitle) => { - const fixturePath = path.join(__dirname, 'fixtures', 'python-xunit.xml') - const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) - const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) - - const opts: ParseOptions = { - parseErrors: true, - trackedFiles: [] - } - - const parser = new PythonXunitParser(opts) + const parser = new PythonXunitParser(defaultOpts) const result = await parser.parse(filePath, fileContent) const report = getReport([result], { ...DEFAULT_OPTIONS, @@ -71,16 +58,7 @@ describe('python-xunit tests', () => { }) it('report includes a custom report title', async () => { - const fixturePath = path.join(__dirname, 'fixtures', 'python-xunit.xml') - const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) - const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) - - const opts: ParseOptions = { - parseErrors: true, - trackedFiles: [] - } - - const parser = new PythonXunitParser(opts) + const parser = new PythonXunitParser(defaultOpts) const result = await parser.parse(filePath, fileContent) const report = getReport([result], { ...DEFAULT_OPTIONS,