Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape skip reason in junitxml #11842

Merged
merged 8 commits into from Jan 19, 2024
Merged

Escape skip reason in junitxml #11842

merged 8 commits into from Jan 19, 2024

Conversation

clee2000
Copy link
Contributor

@clee2000 clee2000 commented Jan 18, 2024

Escape invalid characters in the skip message in junitxml.

Small repro:

import pytest

class TestA:
    @pytest.mark.skip("\33[31;1madsfsd\33[0m")
    def test_a(self):
        assert 2 == 2

Run the above via pytest repro.py --junit-xml=repro.xml
The result is (formatted for easier reading):

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
    <testsuite name="pytest" errors="0" failures="0" skipped="1" tests="1" time="0.045"
        timestamp="2024-01-18T09:38:22.499385" hostname="csl-mbp">
        <testcase classname="repro.TestA" name="test_a" time="0.000">
            <skipped type="pytest.skip" message="�[31;1mrandom colored skip reason�[0m">/Users/csl/zzzzzzzz/random-testing/repro.py:4:
                #x1B[31;1mrandom colored skip reason#x1B[0m</skipped>
        </testcase>
    </testsuite>
</testsuites>

There's an invalid XML character (Unicode 0x1b) in the message that prevents me from parsing the XML.
The output after this change is:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
    <testsuite name="pytest" errors="0" failures="0" skipped="1" tests="1" time="0.037"
        timestamp="2024-01-18T09:39:55.805037" hostname="csl-mbp">
        <testcase classname="repro.TestA" name="test_a" time="0.000">
            <skipped type="pytest.skip" message="#x1B[31;1mrandom colored skip reason#x1B[0m">/Users/csl/zzzzzzzz/random-testing/repro.py:4:
                #x1B[31;1mrandom colored skip reason#x1B[0m</skipped>
        </testcase>
    </testsuite>
</testsuites>

@nicoddemus
Copy link
Member

Awesome, thanks for the PR @clee2000!

Could you please add a test to https://github.com/pytest-dev/pytest/blob/main/testing/test_junitxml.py for completeness and to avoid a future regression?

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @clee2000, appreciate it!

@nicoddemus nicoddemus merged commit d71ef04 into pytest-dev:main Jan 19, 2024
24 checks passed
jsuchenia pushed a commit to jsuchenia/adventofcode that referenced this pull request Jan 29, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [pytest](https://docs.pytest.org/en/latest/) ([source](https://github.com/pytest-dev/pytest), [changelog](https://docs.pytest.org/en/stable/changelog.html)) | dev | major | `7.4.4` -> `8.0.0` |

---

### Release Notes

<details>
<summary>pytest-dev/pytest (pytest)</summary>

### [`v8.0.0`](https://github.com/pytest-dev/pytest/releases/tag/8.0.0): pytest 8.0.0 (2024-01-27)

[Compare Source](pytest-dev/pytest@7.4.4...8.0.0)

See [8.0.0rc1](https://github.com/pytest-dev/pytest/releases/tag/8.0.0rc1) and [8.0.0rc2](https://github.com/pytest-dev/pytest/releases/tag/8.0.0rc2) for the full changes since pytest 7.4!

#### Bug Fixes

-   [#&#8203;11842](pytest-dev/pytest#11842): Properly escape the `reason` of a `skip <pytest.mark.skip ref>`{.interpreted-text role="ref"} mark when writing JUnit XML files.
-   [#&#8203;11861](pytest-dev/pytest#11861): Avoid microsecond exceeds `1_000_000` when using `log-date-format` with `%f` specifier, which might cause the test suite to crash.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjEzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=-->

Reviewed-on: https://git.apud.pl/jacek/adventofcode/pulls/52
Co-authored-by: Renovate <renovate@apud.pl>
Co-committed-by: Renovate <renovate@apud.pl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants