Skip to content

Commit 82c5a88

Browse files
author
Alex Remedios
authored
junit fix (#8)
1 parent f21d090 commit 82c5a88

6 files changed

Lines changed: 64 additions & 6 deletions

File tree

python-cli/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ addopts = [
3939
"--strict-markers",
4040
# "--capture=tee-sys",
4141
"--forked"
42-
]
42+
]
43+
44+
[tool.poetry.plugins."pytest11"]
45+
deeptest = "deeptest.pytest_plugin"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import shutil
2+
from typing import Any
3+
4+
from _pytest.config import Config
5+
from pytest import ExitCode
6+
7+
out_path = ".deeptest/junit.xml"
8+
9+
10+
def pytest_configure(config):
11+
if config.option.xmlpath is None:
12+
config.option.xmlpath = out_path
13+
14+
15+
def pytest_terminal_summary(
16+
terminalreporter: Any, exitstatus: ExitCode, config: Config
17+
):
18+
if not config.option.xmlpath == out_path:
19+
print(f"Copying {config.option.xmlpath} to {out_path}")
20+
shutil.copy(config.option.xmlpath, out_path)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[pytest]
22
addopts =
33
--cov=src
4-
--cov-context=test
5-
--junit-xml=.deeptest/junit.xml
4+
--cov-context=test

python-cli/tests/test_cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
from click.testing import CliRunner
66
from deeptest.cli import File
77
from snapshottest.pytest import PyTestSnapshotTest
8+
from tests.util import RESOURCES
89

910
from deeptest import cli
1011

1112
pytest_plugins = "pytester"
1213
import shutil
1314
import sys
14-
from pathlib import Path
1515
from subprocess import CalledProcessError, check_output
1616

17-
RESOURCES = (Path(__file__) / ".." / "resources").resolve()
18-
1917

2018
@pytest.fixture
2119
def tested_dir():
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import print_function
2+
3+
from distutils.dir_util import copy_tree
4+
from pathlib import Path
5+
6+
import pytest
7+
from _pytest.pytester import Testdir
8+
from pytest import ExitCode
9+
from tests.util import RESOURCES
10+
11+
pytest_plugins = "pytester"
12+
NB_VERSION = 4
13+
import shutil
14+
15+
16+
@pytest.fixture
17+
def fake_repo(testdir: Testdir):
18+
copy_tree(RESOURCES.as_posix(), ".")
19+
20+
21+
def test_when_no_xml_then_output_correctly(testdir: Testdir, fake_repo: object):
22+
shutil.rmtree(".deeptest", ignore_errors=True)
23+
hook_recorder = testdir.inline_run()
24+
25+
assert hook_recorder.ret == ExitCode.TESTS_FAILED
26+
assert Path(".deeptest/junit.xml").exists()
27+
28+
29+
def test_when_other_xml_then_output_correctly(testdir: Testdir, fake_repo: object):
30+
shutil.rmtree(".deeptest", ignore_errors=True)
31+
hook_recorder = testdir.inline_run("--junit-xml=junit.xml")
32+
33+
assert hook_recorder.ret == ExitCode.TESTS_FAILED
34+
assert Path(".deeptest/junit.xml").exists()
35+
assert Path("junit.xml").exists()

python-cli/tests/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from pathlib import Path
2+
3+
RESOURCES = (Path(__file__) / ".." / "resources").resolve()

0 commit comments

Comments
 (0)