pytest-dev / pytest-dev/pytest

some test cases not being found when running pytest.main(['--co']) due to Unicode-encoded test case names

Open
#11,202 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: collection
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

  • a detailed description of the bug or problem you are having
    why test_cases/test_product/demo/demo7_pytest_main.py::TestClass_A::test_demo[\u6d4b\u8bd5\u7528\u4f8b\u540d\u79f0P2] in case_list was not found in the specified module. but in case_list02 it was found
#demo.py
class TestClass_A: 
   @pytest.mark.parametrize("case_lel,id,", [('测试用例名称P0',0),('测试用例名称P1',6),('hzhzhzhzP0',1),('测试用例名称P2',2),('hzhzhzhzP2',3)],ids=[('测试用例名称P0'),('测试用例名称P1'),('hzhzhzhzP0'),('测试用例名称P2'),('hzhzhzhzP2')]) 
   def test_demo(self,case_lel,id): 
          print(id) 
if __name__ == '__main__': 
   case_list=['demo/demo7_pytest_main.py::TestClass_A::test_demo[\\u6d4b\\u8bd5\\u7528\\u4f8b\\u540d\\u79f0P0]','demo/demo7_pytest_main.py::TestClass_A::test_demo[\\u6d4b\\u8bd5\\u7528\\u4f8b\\u540d\\u79f0P1]', 'demo/demo7_pytest_main.py::TestClass_A::test_demo[hzhzhzhzP0]', 'demo/demo7_pytest_main.py::TestClass_A::test_demo[\\u6d4b\\u8bd5\\u7528\\u4f8b\\u540d\\u79f0P2]', 'demo/demo7_pytest_main.py::TestClass_A::test_demo[hzhzhzhzP2]'] 
   for i in case_list: 
         pytest.main([i,'--co'])


========================================================================= test session starts ==========================================================================
platform win32 -- Python 3.10.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: d:\autotest\interface-autotest-pytest, configfile: pytest.ini
plugins: allure-pytest-2.9.43, anyio-3.6.2, Faker-15.2.0, forked-1.3.0, ordering-0.6, parallel-0.0.10, repeat-0.9.1, rerunfailures-10.0, timeout-2.1.0, xdist-2.3.0      
collecting ... 2023-07-13 10:20:06,453 [pid:53784] INFO [FILE:conftest.py:271 FUN:pytest_collection_modifyitems]: 测试用例名称:['test_demo[测试用例名称P0]']
2023-07-13 10:20:06,453 [pid:53784] INFO [FILE:conftest.py:272 FUN:pytest_collection_modifyitems]: 测试用例文件路径:['test_cases/test_product/demo/demo7_pytest_main.py::TestClass_A::test_demo[测试用例名称P0]']
collected 1 item                                                                                                                                                         

<Package demo>
  <Module demo7_pytest_main.py>
    <Class TestClass_A>
        <Function test_demo[测试用例名称P0]>

收集测试用例结果
2023-07-13 10:20:06,457 [pid:53784] INFO [FILE:conftest.py:74 FUN:pytest_terminal_summary]: total: 1; passed: 0; failed: 0; skipped: 0; error: 0; duration: 0.03
====================================================================== 1 test collected in 0.03s ======================================================================= 
========================================================================= test session starts ==========================================================================
platform win32 -- Python 3.10.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: d:\autotest\interface-autotest-pytest, configfile: pytest.ini
plugins: allure-pytest-2.9.43, anyio-3.6.2, Faker-15.2.0, forked-1.3.0, ordering-0.6, parallel-0.0.10, repeat-0.9.1, rerunfailures-10.0, timeout-2.1.0, xdist-2.3.0      
collected 0 items                                                                                                                                                        

收集测试用例结果
2023-07-13 10:20:06,557 [pid:53784] INFO [FILE:conftest.py:74 FUN:pytest_terminal_summary]: total: 0; passed: 0; failed: 0; skipped: 0; error: 0; duration: 0.02
===================================================================== no tests collected in 0.03s ====================================================================== 
ERROR: not found: d:\autotest\interface-autotest-pytest\test_cases\test_product\demo\demo7_pytest_main.py::TestClass_A::test_demo[\u6d4b\u8bd5\u7528\u4f8b\u540d\u79f0P1](no name 'd:\\autotest\\interface-autotest-pytest\\test_cases\\test_product\\demo\\demo7_pytest_main.py::TestClass_A::test_demo[\\u6d4b\\u8bd5\\u7528\\u4f8b\\u540d\\u79f0P1]' in any of [<Module demo7_pytest_main.py>])

========================================================================= test session starts ==========================================================================
platform win32 -- Python 3.10.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: d:\autotest\interface-autotest-pytest, configfile: pytest.ini
plugins: allure-pytest-2.9.43, anyio-3.6.2, Faker-15.2.0, forked-1.3.0, ordering-0.6, parallel-0.0.10, repeat-0.9.1, rerunfailures-10.0, timeout-2.1.0, xdist-2.3.0      
collecting ... 2023-07-13 10:20:06,665 [pid:53784] INFO [FILE:conftest.py:271 FUN:pytest_collection_modifyitems]: 测试用例名称:['test_demo[hzhzhzhzP0]']
2023-07-13 10:20:06,665 [pid:53784] INFO [FILE:conftest.py:272 FUN:pytest_collection_modifyitems]: 测试用例文件路径:['test_cases/test_product/demo/demo7_pytest_main.py::TestClass_A::test_demo[hzhzhzhzP0]']
collected 1 item                                                                                                                                                         

<Package demo>
  <Module demo7_pytest_main.py>
    <Class TestClass_A>
        <Function test_demo[hzhzhzhzP0]>

收集测试用例结果
2023-07-13 10:20:06,670 [pid:53784] INFO [FILE:conftest.py:74 FUN:pytest_terminal_summary]: total: 1; passed: 0; failed: 0; skipped: 0; error: 0; duration: 0.03
====================================================================== 1 test collected in 0.03s ======================================================================= 
========================================================================= test session starts ==========================================================================
platform win32 -- Python 3.10.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: d:\autotest\interface-autotest-pytest, configfile: pytest.ini
plugins: allure-pytest-2.9.43, anyio-3.6.2, Faker-15.2.0, forked-1.3.0, ordering-0.6, parallel-0.0.10, repeat-0.9.1, rerunfailures-10.0, timeout-2.1.0, xdist-2.3.0      
collected 0 items                                                                                                                                                        

收集测试用例结果
2023-07-13 10:20:06,780 [pid:53784] INFO [FILE:conftest.py:74 FUN:pytest_terminal_summary]: total: 0; passed: 0; failed: 0; skipped: 0; error: 0; duration: 0.02
===================================================================== no tests collected in 0.02s ====================================================================== 
ERROR: not found: d:\autotest\interface-autotest-pytest\test_cases\test_product\demo\demo7_pytest_main.py::TestClass_A::test_demo[\u6d4b\u8bd5\u7528\u4f8b\u540d\u79f0P2](no name 'd:\\autotest\\interface-autotest-pytest\\test_cases\\test_product\\demo\\demo7_pytest_main.py::TestClass_A::test_demo[\\u6d4b\\u8bd5\\u7528\\u4f8b\\u540d\\u79f0P2]' in any of [<Module demo7_pytest_main.py>])

========================================================================= test session starts ==========================================================================
platform win32 -- Python 3.10.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: d:\autotest\interface-autotest-pytest, configfile: pytest.ini
plugins: allure-pytest-2.9.43, anyio-3.6.2, Faker-15.2.0, forked-1.3.0, ordering-0.6, parallel-0.0.10, repeat-0.9.1, rerunfailures-10.0, timeout-2.1.0, xdist-2.3.0      
collecting ... 2023-07-13 10:20:06,892 [pid:53784] INFO [FILE:conftest.py:271 FUN:pytest_collection_modifyitems]: 测试用例名称:['test_demo[hzhzhzhzP2]']
2023-07-13 10:20:06,892 [pid:53784] INFO [FILE:conftest.py:272 FUN:pytest_collection_modifyitems]: 测试用例文件路径:['test_cases/test_product/demo/demo7_pytest_main.py::TestClass_A::test_demo[hzhzhzhzP2]']
collected 1 item                                                                                                                                                         

<Package demo>
  <Module demo7_pytest_main.py>
    <Class TestClass_A>
        <Function test_demo[hzhzhzhzP2]>

收集测试用例结果
2023-07-13 10:20:06,897 [pid:53784] INFO [FILE:conftest.py:74 FUN:pytest_terminal_summary]: total: 1; passed: 0; failed: 0; skipped: 0; error: 0; duration: 0.03
====================================================================== 1 test collected in 0.03s ======================================================================= 
#demo02.py
class TestClass_A: 
   @pytest.mark.parametrize("case_lel,id,", [('测试用例名称P0',0),('测试用例名称P1',6),('hzhzhzhzP0',1),('测试用例名称P2',2),('hzhzhzhzP2',3)],ids=[('测试用例名称P0'),('测试用例名称P1'),('hzhzhzhzP0'),('测试用例名称P2'),('hzhzhzhzP2')]) 
   def test_demo(self,case_lel,id): 
          print(id) 
if __name__ == '__main__': 
   case_list02 =['demo7_pytest_main.py::TestClass_A::test_demo[\\u6d4b\\u8bd5\\u7528\\u4f8b\\u540d\\u79f0P2]']
   for i in case_list: 
         pytest.main([i,'--co'])


======================================================================== test session starts ==========================================================================
platform win32 -- Python 3.10.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: d:\autotest\interface-autotest-pytest, configfile: pytest.ini
plugins: allure-pytest-2.9.43, anyio-3.6.2, Faker-15.2.0, forked-1.3.0, ordering-0.6, parallel-0.0.10, repeat-0.9.1, rerunfailures-10.0, timeout-2.1.0, xdist-2.3.0      
collecting ... 2023-07-13 10:17:13,975 [pid:61924] INFO [FILE:conftest.py:271 FUN:pytest_collection_modifyitems]: 测试用例名称:['test_demo[测试用例名称P2]']
2023-07-13 10:17:13,975 [pid:61924] INFO [FILE:conftest.py:272 FUN:pytest_collection_modifyitems]: 测试用例文件路径:['test_cases/test_product/demo/demo7_pytest_main.py::TestClass_A::test_demo[测试用例名称P2]']
collected 1 item                                                                                                                                                         

<Package demo>
  <Module demo7_pytest_main.py>
    <Class TestClass_A>
        <Function test_demo[测试用例名称P2]>

收集测试用例结果
2023-07-13 10:17:13,979 [pid:61924] INFO [FILE:conftest.py:74 FUN:pytest_terminal_summary]: total: 1; passed: 0; failed: 0; skipped: 0; error: 0; duration: 0.03
  • output of pip list from the virtual environment you are using
Package                   Version
allure-pytest             2.9.43
allure-python-commons     2.9.43
altgraph                  0.17.2
anyio                     3.6.2
arrow                     1.2.3
asgiref                   3.6.0
astroid                   2.15.1
async-timeout             4.0.2
atomicwrites              1.4.0
attrs                     21.2.0
autopep8                  2.0.2
bcrypt                    4.0.1
certifi                   2021.5.30
cffi                      1.15.1
chardet                   4.0.0
charset-normalizer        2.0.12
click                     8.1.3
colorama                  0.4.4
conf                      0.4.1
configobj                 5.0.6
configparser              5.2.0
contourpy                 1.0.6
cryptography              38.0.1
cx-Oracle                 8.3.0
cycler                    0.11.0
dataclasses               0.6
Deprecated                1.2.13
dill                      0.3.6
distlib                   0.3.4
Django                    4.1.7
djangorestframework       3.14.0
docstring-to-markdown     0.12
dvadmin-ak-sk             1.0.0
dynaconf                  3.1.4
et-xmlfile                1.1.0
exceptiongroup            1.1.1
execnet                   1.9.0
Faker                     15.2.0
fastapi                   0.89.1
filelock                  3.6.0
flake8                    6.0.0
fonttools                 4.38.0
future                    0.18.2
gevent                    22.10.1
greenlet                  1.1.3.post0
h11                       0.14.0
idna                      2.10
iniconfig                 1.1.1
isort                     5.12.0
jedi                      0.18.2
JPype1                    1.4.0
jsonpath                  0.82
kiwisolver                1.4.4
lazy-object-proxy         1.9.0
lxml                      4.9.2
matplotlib                3.6.2
mccabe                    0.7.0
numpy                     1.22.3
openpyxl                  3.0.10
packaging                 20.9
pandas                    1.4.2
paramiko                  2.11.0
parso                     0.8.3
pefile                    2021.9.3
pika                      1.3.0
Pillow                    9.3.0
pip                       22.3.1
platformdirs              2.5.2
pluggy                    0.13.1
psycopg2                  2.9.3
py                        1.10.0
pyasn1                    0.4.8
pycodestyle               2.10.0
pycparser                 2.21
pycryptodome              3.14.1
pydantic                  1.10.4
pydocstyle                6.3.0
pyflakes                  3.0.1
pyinstaller               4.10
pyinstaller-hooks-contrib 2022.3
pylint                    2.17.1
pymongo                   4.2.0
PyMySQL                   1.0.2
PyNaCl                    1.5.0
pyparsing                 2.4.7
pytest                    6.2.4
pytest-forked             1.3.0
pytest-ordering           0.6
pytest-parallel           0.0.10
pytest-repeat             0.9.1
pytest-rerunfailures      10.0
pytest-timeout            2.1.0
pytest-xdist              2.3.0
python-dateutil           2.8.2
python-editor             1.0.4
python-lsp-jsonrpc        1.0.0
python-lsp-server         1.7.2
pytoolconfig              1.2.5
pytz                      2023.3
pywin32-ctypes            0.2.0
PyYAML                    6.0
redis                     4.3.4
redis-py-cluster          2.1.3
requests                  2.27.1
rope                      1.7.0
rsa                       4.8
ruamel.yaml               0.16.12
setuptools                62.1.0
six                       1.16.0
sniffio                   1.3.0
snowballstemmer           2.2.0
sqlparse                  0.4.3
starlette                 0.22.0
tblib                     1.7.0
toml                      0.10.2
tomli                     2.0.1
tomlkit                   0.11.7
typing_extensions         4.4.0
tzdata                    2022.7
ujson                     5.7.0
urllib3                   1.26.6
uvicorn                   0.20.0
virtualenv                20.14.1
whatthepatch              1.0.4
wrapt                     1.14.1
xlrd                      2.0.1
xlrd2                     1.3.4
xlwt                      1.3.0
XMind                     1.2.0
xmindparser               1.0.9
yapf                      0.32.0
zope.event                4.5.0
zope.interface            5.5.0
  • pytest and operating system versions
platform linux  
Python 3.8.8, 
pytest-6.2.4, 
py-1.10.0, 
pluggy-0.13.1 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproductions in demo.py and demo02.py and run the shown pytest.main(['--co']) commands against the parametrized test names. Compare collection of the Unicode-encoded names with the direct Unicode name, then verify that both encoded P1 and P2 node IDs are collected successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.