Skip to content

Comments

fix: swev-id: pytest-dev__pytest-5809 use text lexer for bpaste#21

Open
casey-brooks wants to merge 1 commit intopytest-dev__pytest-5809from
fix/pastebin-lexer-text-5809
Open

fix: swev-id: pytest-dev__pytest-5809 use text lexer for bpaste#21
casey-brooks wants to merge 1 commit intopytest-dev__pytest-5809from
fix/pastebin-lexer-text-5809

Conversation

@casey-brooks
Copy link

Summary

  • send bpaste pastes with lexer=text to avoid HTTP 400 responses
  • update pastebin test expectations to cover the new lexer value

Issue

Closes #15

Reproduction

  1. Save the following script as repro_python3.py (use https://bpa.st, the current bpaste endpoint):
    from urllib.request import urlopen
    from urllib.parse import urlencode
    
    url = "https://bpa.st"
    contents = b"============================= test session starts =============================\nplatform linux -- Python 3.12.1, pytest-9.0.2, pluggy-1.5.0\nrootdir: /tmp/demo, inifile=\ncollected 1 item\n\n test_example.py F\n\n=================================== FAILURES ===================================\n..."
    params = {"code": contents, "lexer": "python3", "expiry": "1week"}
    urlopen(url, data=urlencode(params).encode("ascii")).read()
  2. Run the script with Python 3.8 (python repro_python3.py) and observe the failure:
    Traceback (most recent call last):
      File "repro_python3.py", line 9, in <module>
        urlopen(url, data=urlencode(params).encode("ascii")).read()
      File "/root/.pyenv/versions/3.8.18/lib/python3.8/urllib/request.py", line 222, in urlopen
        return opener.open(url, data, timeout)
      File "/root/.pyenv/versions/3.8.18/lib/python3.8/urllib/request.py", line 531, in open
        response = meth(req, response)
      File "/root/.pyenv/versions/3.8.18/lib/python3.8/urllib/request.py", line 640, in http_response
        response = self.parent.error(
      File "/root/.pyenv/versions/3.8.18/lib/python3.8/urllib/request.py", line 569, in error
        return self._call_chain(*args)
      File "/root/.pyenv/versions/3.8.18/lib/python3.8/urllib/request.py", line 502, in _call_chain
        result = func(*args)
      File "/root/.pyenv/versions/3.8.18/lib/python3.8/urllib/request.py", line 649, in http_error_default
        raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 400: Bad Request
    
  3. Save the success script as verify_text.py:
    from urllib.request import urlopen
    from urllib.parse import urlencode
    import re
    
    url = "https://bpa.st"
    contents = b"============================= test session starts =============================\nplatform linux -- Python 3.12.1, pytest-9.0.2, pluggy-1.5.0\nrootdir: /tmp/demo, inifile=\ncollected 1 item\n\n test_example.py F\n\n=================================== FAILURES ===================================\n..."
    params = {"code": contents, "lexer": "text", "expiry": "1week"}
    html = urlopen(url, data=urlencode(params).encode("ascii")).read().decode("utf-8")
    match = re.search(r'href="/raw/(\\w+)"', html)
    if match:
        print("Show URL:", f"{url}/show/{match.group(1)}")
  4. Run python verify_text.py and confirm the HTML response includes a working paste URL such as:
    <!doctype html>
    Show URL: https://bpa.st/show/MWKA
    

Verification

  • .venv/bin/python -m pytest testing/test_pastebin.py (Python 3.8.18)

@casey-brooks casey-brooks requested a review from a team December 25, 2025 20:40
@casey-brooks casey-brooks force-pushed the fix/pastebin-lexer-text-5809 branch from 1ddee8c to 4f72460 Compare December 25, 2025 20:45
@casey-brooks
Copy link
Author

Local validation:\n- python3.8 -m pytest testing/test_pastebin.py — 4 passed / 0 failed / 0 skipped\n- black --check src/_pytest/pastebin.py testing/test_pastebin.py\n- flake8 src/_pytest/pastebin.py testing/test_pastebin.py

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Change looks good—switching to the text lexer and updating the test expectation resolves the bpaste 400 issue.

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.

2 participants