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

Test not published to Report Portal when docstring or parameter contains \0 #382

Open
AlexLitvino opened this issue Nov 20, 2024 · 0 comments
Labels

Comments

@AlexLitvino
Copy link

Result for test is not published to Report Portal when \0 is contained in:

  • docstring
  • value for parameterization

Steps to Reproduce
Run the following tests with publishing result to Report Portal:

def test_with_slash_zero_in_docstring():
    """This test verifies publishing \0 to Report Portal"""
    pass

import pytest

@pytest.mark.parametrize('param', ['1\0',])
def test_with_param_with_slash_zero(param):
    pass

Expected behavior
Test result is published to Report Portal (test launch is created with test items inside).

Actual behavior
Test launch is created but they are empty, doesn't contain any tests.

Sniffing packets with WireShark, the following Start root(suite) item requests were sent for the 1st and the 2nd tests:
POST /api/v2/my_project/item
{"codeRef": "tests/test_example.py:test_with_slash_zero_in_docstring", "description": "This test verifies publishing \u0000 to Report Portal", "hasStats": true, "name": "tests/test_example.py::test_with_slash_zero_in_docstring", "retry": false, "retryOf": null, "startTime": "1732110741030", "testCaseId": "tests/test_example.py:test_with_slash_zero_in_docstring", "type": "STEP", "launchUuid": "b354fc52-5f18-4120-a864-3d531bab7077", "attributes": [], "parameters": null}

POST /api/v2/my_project/item
{"codeRef": "tests/test_example.py:test_with_param_with_slash_zero", "description": null, "hasStats": true, "name": "tests/test_example.py::test_with_param_with_slash_zero[1\x00]", "retry": false, "retryOf": null, "startTime": "1732111412360", "testCaseId": "tests/test_example.py:test_with_param_with_slash_zero[1\u0000]", "type": "STEP", "launchUuid": "4fd5a4cd-522e-495b-b356-1b6b00f35d36", "attributes": [], "parameters": [{"key": "param", "value": "1\u0000"}]}:

Package versions
pytest 8.3.2
pytest-reportportal 5.4.5
reportportal-client 5.5.9

Note that if \0 is placed at the end of docstring line, result is published to Report Portal, though request contains \u000:
"description": "This test verifies publishing \u0000"

Also general issue here might be not escaping back slash. For example for test

def test_with_docstring_with_slash_n():
    """Test to verify publishing with new line

    Precondition
    - Create file

    Action
    - Write string 'A\nB' to the file

    Result
    - File contains string 'A\nB'
    """
    pass

We get results as on image below. Not sure if it is should be separate issue.
TestResultWithNewLine
And because of usage expandtabs in trim_docstring function of pytest_reportportal we got 8 whitespaces instead of \t.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant