ITADN

test case doesn't match pytest -k"name"

#14476Openzjj831219 创建于 2026-05-13
Z
zjj831219commented
<!-- Thanks for submitting an issue! Quick check-list while reporting bugs: --> command is: pytest --collect-only -k"baidu and not logo" but test result is : (.venv) PS D:\project\vscode\src> pytest --collect-only -k"baidu and not logo" ============================================================ test session starts ============================================================= platform win32 -- Python 3.14.0, pytest-9.0.3, pluggy-1.6.0 rootdir: D:\project\vscode\src collected 9 items / 3 deselected / 6 selected <Dir src> <Module test_web.py> <Function test_baidu> <Class Test_web> <Function test_baidu_in_class> <Function test_class_mark> <Function test_parametrize[1-2]> <Function test_parametrize[7-6]> <Function test_parametrize[5-3]> after running pytest --collect-only -k" baidu and not logo", test_parametrize() and test_class_mark () are also selected and tested ,there is no "baidu"in their names , but should be deselected (.venv) PS D:\project\vscode\src> pip list Package Version ------------------ ----------- attrs 26.1.0 certifi 2026.2.25 cffi 2.0.0 charset-normalizer 3.4.7 colorama 0.4.6 h11 0.16.0 idna 3.11 iniconfig 2.3.0 outcome 1.3.0.post0 packaging 26.0 pip 25.2 pluggy 1.6.0 pycparser 3.0 Pygments 2.20.0 PyMySQL 1.1.2 PySocks 1.7.1 pytest 9.0.3 requests 2.33.1 selenium 4.43.0 sniffio 1.3.1 sortedcontainers 2.4.0 trio 0.33.0 trio-websocket 0.12.2 typing_extensions 4.15.0 urllib3 2.6.3 websocket-client 1.9.0 wsproto 1.3.2 #systeminfo 主机名: STONE OS 名称: Microsoft Windows 11 home Chinese edition OS version: 10.0.26100 暂缺 Build 26100 Python: 3.14.0 pytest :9.0.3 - [ ] minimal example if possible #test_web.py import pytest import requests pytestmark = [pytest.mark.webtest,pytest.mark.baidu_test] def test_baidu(): res = requests.get('http://www.baidu.com') print(f'status code = {res.status_code}') assert res.status_code == 200 def test_baidu_logo(): res = requests.get('http://www.baidu.com') print(f'status code = {res.status_code}') assert res.status_code == 200 assert 'logo' in res.text @pytest.mark.baidu_test def test_baidu_logo_mark(): res = requests.get('http://www.baidu.com') print(f'status code = {res.status_code}') assert res.status_code == 200 assert 'logo' in res.text class Test_web: pytestmark=[pytest.mark.class_webtest,pytest.mark.slow] def setup_class(self): self.url = 'http://www.baidu.com' print(f'setup_class: this is Test_web class, url = {self.url}') def test_baidu_in_class(self): res = requests.get(self.url) print(f'status code = {res.status_code}') assert res.status_code == 200 def test_baidu_logo_in_class(self): res = requests.get(self.url) print(f'status code = {res.status_code}') assert res.status_code == 200 assert 'logo' in res.text def test_class_mark(): test = Test_web() @pytest.mark.batch @pytest.mark.parametrize("a,b",[(1,2),(7,6),(5,3)]) def test_parametrize(a,b): print(f'a = {a}, b = {b}') c = lambda a,b:a*b assert c != 0
1 条评论