Skip to content

pytest parameterized tests with randomly generate names #22648

@cquick01

Description

@cquick01

Type: Bug

Behaviour

Expected vs. Actual

When running pytest via VSCode, I get the following errors

Running tests (pytest): /home/user/test/tests/test_bytes.py::test_randbytes
Running test with arguments: --rootdir /home/user/test --override-ini junit_family=xunit1 --junit-xml=/tmp/tmp-522739qc0UGxP1z6FD.xml --capture no ./tests/test_bytes.py::test_randbytes
Current working directory: /home/user/test
Workspace directory: /home/user/test
Run completed, parsing output
Test result not found for: ./tests/test_bytes.py::test_randbytes[b8\xef\xef]

Test result not found for: ./tests/test_bytes.py::test_randbytes[\xb4d\xed\xaek\xac\xdbR\xde\xe2\x87\xcc5\x9c]\x95\x02.\xac\xd1)\x8a\xb3\xaf\x15\x87\xad\x83c\x0b\x94Z\x8d\x03\xcd<\xd6\xa0\xe9\xba\x11\x95]

Test result not found for: ./tests/test_bytes.py::test_randbytes[5?5\x9cIGQG\xba\x8a\xdb\xf7\xc8\xec k\x95\x08\xbb \x8c\x1eBb\xd33\x93\x1c\x93\xe6\xc2\x08\x7f\xd1\xa7\x95\xf5m\xca\xaa\xe2\x90\x8c\x97\x80\xfe\xd0\xd2#\xbdI\x1dV3>\x8e7\x01\xffg\r]

Test result not found for: ./tests/test_bytes.py::test_randbytes[k[\x02M\xe2\r*\xcd4\xc2Q+\xadbqP\xca\xac\xc4]

Test result not found for: ./tests/test_bytes.py::test_randbytes[\xdb\x1d\xe8\x04\n\x9b\x0b/.\xd55\xd2\x92\xbf\x05/\xc1\xa0\x06\x95\xd2s\x18\xd1\xed'\xd9Cu\x02S\xe1\x0b\xc4\xa6\x00)\xda\xf1]

Test result not found for: ./tests/test_bytes.py::test_randbytes[\xe4\x94`\xd0\xb9V\x97g%\xafa\xda\xc8\xd1\xbd\xd7\xc5Z\xf7\xb7\xdf\xbdd]

Test result not found for: ./tests/test_bytes.py::test_randbytes[\xb2\x8f]

Test result not found for: ./tests/test_bytes.py::test_randbytes[z:\x1f\xccq`\xd6\x88\xef\x8a\xbc*\x8f\x95\x8e\x8c\xf9O\xf1\xdbo(]

Test result not found for: ./tests/test_bytes.py::test_randbytes[\xd5h[\x7f\xe2\xf6m\xf1]

Test result not found for: ./tests/test_bytes.py::test_randbytes[_\x82p\xac\x07\xc1\xdbO\n\xe1<\x19\xb2\xbbW\x18\x95\x02H\xc8]

Total number of tests expected to run: 10
Total number of tests run: 0
Total number of tests passed: 0
Total number of tests failed: 0
Total number of tests failed with errors: 0
Total number of tests skipped: 0
Total number of tests with no result data: 10
Finished running tests!

But the debug window shows that it passes

============================= test session starts ==============================
platform linux -- Python 3.11.3, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/user/test
collected 10 items

tests/test_bytes.py ..........

------------- generated xml file: /tmp/tmp-522739qc0UGxP1z6FD.xml --------------
============================== 10 passed in 0.10s ==============================

And it works fine when running on command line.

Steps to reproduce:

  1. Setup Environment
.
├── poetry.lock
├── pyproject.toml
└── tests
    └── test_bytes.py

test_bytes.py

#!/usr/bin/env python3
import random

import pytest

RANDOM_BYTES = [random.randbytes(random.randint(0, 64)) for _ in range(10)]


@pytest.mark.parametrize("data", RANDOM_BYTES)
def test_randbytes(data):
    foo = data
    assert foo == data

pyproject.toml

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = ["User <user@domain.tld>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
pytest = "^7.4.3"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
  1. Install with poetry
pip install poetry  # if needed
poetry lock
poetry install
  1. Configure Python interpreter in VSCode
# to get path of environment
poetry env info -p
  1. Run tests, errors occur. Running pytest in terminal passes.

Edit: Also, when adding this test with ints, most fail the same way, but two of them seem to pass.

image

But the debug window still shows all tests pass, 20 this time

============================= test session starts ==============================
platform linux -- Python 3.11.3, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/cquick/test
collected 20 items

tests/test_bytes.py ....................

------------- generated xml file: /tmp/tmp-522739BQWWvKOgqoHN.xml --------------
============================== 20 passed in 0.10s ==============================

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.3
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Poetry
  • Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

2023-12-13 17:19:53.199 [debug] Clearing context for python dependencies not installed: /home/user/test/pyproject.toml
2023-12-13 17:19:53.202 [debug] Found cached env for /home/user/.cache/pypoetry/virtualenvs/test-zxyBamcN-py3.11/bin/python3
2023-12-13 17:19:53.202 [debug] Found cached env for /home/user/.cache/pypoetry/virtualenvs/test-zxyBamcN-py3.11/bin/python3
2023-12-13 17:19:53.219 [debug] Found cached env for /home/user/.cache/pypoetry/virtualenvs/test-zxyBamcN-py3.11/bin/python3
2023-12-13 17:19:53.234 [info] > ~/.cache/pypoetry/virtualenvs/test-zxyBamcN-py3.11/bin/python3 -m pytest --rootdir . --override-ini junit_family=xunit1 --junit-xml=/tmp/tmp-5227399oU3WLyyfScP.xml
2023-12-13 17:19:53.234 [info] cwd: .
2023-12-13 17:19:57.440 [debug] Clearing context for python dependencies not installed: ms-python.python.Python
2023-12-13 17:19:57.440 [debug] Found cached env for /home/user/.cache/pypoetry/virtualenvs/test-zxyBamcN-py3.11/bin/python3
2023-12-13 17:20:03.697 [debug] Clearing context for python dependencies not installed: /home/user/test/pyproject.toml
2023-12-13 17:20:03.700 [debug] Found cached env for /home/user/.cache/pypoetry/virtualenvs/test-zxyBamcN-py3.11/bin/python3
2023-12-13 17:20:11.268 [debug] Clearing context for python dependencies not installed: ms-python.python.Python
2023-12-13 17:20:11.268 [debug] Found cached env for /home/user/.cache/pypoetry/virtualenvs/test-zxyBamcN-py3.11/bin/python3

User Settings


languageServer: "Pylance"

testing
• pytestEnabled: true

Extension version: 2023.23.13471011
VS Code version: Code - Insiders 1.86.0-insider (f87fb29, 2023-12-13T08:07:18.340Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Remote OS version: Linux x64 5.15.133.1-microsoft-standard-WSL2

System Info
Item Value
CPUs Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2592)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.70GB (5.56GB free)
Process Argv
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu-22.04
OS Linux x64 5.15.133.1-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2592)
Memory (System) 11.68GB (6.36GB free)
VM 0%

Metadata

Metadata

Assignees

Labels

area-testinginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions