问题
conftest.py
import pytest
from page.loginPage import LoginPage
# 登录ITS
# 可以传入登录的账号名称
# username = 'chenyao007'
@pytest.fixture(scope='class')
def login_ITS(username):
login_ITS = LoginPage()
login = login_ITS.login_ITS(username)
# 鉴权信息
authorization = login[2]+' '+login[3]
# 把鉴权信息放入header中共享给所有接口
login_ITS.session.headers.update({'Authorization':authorization})
fcFirstPage_test.py
from page.fcFirstPage import FCfirstPage
from loguru import logger
import pytest
class TestFCfirstPage():
fcFirstPage = FCfirstPage()
username=['machao341']
# 获取座席信息
pytest.mark.parametrize('login_ITS',
username,
indirect= True)
def test_getUserInfo(self,login_ITS):
response = self.fcFirstPage.getUserInfo()
logger.info(response)
logger.info(response['data']['tmrId'])
assert response['data']['tmrId'] == 'MACHAO341'
报错信息
Testing started at 15:12 ...
D:\workspace\PAC_API_Test\venv\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.7\helpers\pycharm\_jb_pytest_runner.py" --target fcFirstPage_test.py::TestFCfirstPage
Launching pytest with arguments fcFirstPage_test.py::TestFCfirstPage in D:\workspace\PAC_API_Test\test_cases
============================= test session starts =============================
platform win32 -- Python 3.7.0, pytest-7.1.2, pluggy-1.0.0
rootdir: D:\workspace\PAC_API_Test, configfile: pytest.inicollected 1 item
fcFirstPage_test.py E
test setup failed
file D:\workspace\PAC_API_Test\test_cases\fcFirstPage_test.py, line 13
def test_getUserInfo(self,login_ITS):
file D:\workspace\PAC_API_Test\test_cases\conftest.py, line 18
@pytest.fixture(scope='class')
def login_ITS(username):
E fixture 'username' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, login_ITS, login_wizard, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
D:\workspace\PAC_API_Test\test_cases\conftest.py:18
[100%]
=================================== ERRORS ====================================
_____________ ERROR at setup of TestFCfirstPage.test_getUserInfo ______________
file D:\workspace\PAC_API_Test\test_cases\fcFirstPage_test.py, line 13
def test_getUserInfo(self,login_ITS):
file D:\workspace\PAC_API_Test\test_cases\conftest.py, line 18
@pytest.fixture(scope='class')
def login_ITS(username):
E fixture 'username' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, login_ITS, login_wizard, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
D:\workspace\PAC_API_Test\test_cases\conftest.py:18
=========================== short test summary info ===========================
ERROR fcFirstPage_test.py::TestFCfirstPage::test_getUserInfo
============================== 1 error in 0.03s ===============================
Process finished with exit code 0
环境
python3