Web自动化导入问题

问题

selenium执行自动化,在命令行执行会存在导入错误,但是界面执行是正常的,查看过导入信息 没有问题

报错信息

环境

使用sys.path.append 把这项目的目录加到Python的执行环境变量里面就可以了

已解决~根目录下的init文件影响了,删除掉恢复正常额

命令行执行:加上allurdir这块内容就会提示这个(单独执行测试文件是正常的),想问下这种有遇到过吗?

Microsoft Windows [版本 10.0.19045.4170]
(c) Microsoft Corporation。保留所有权利。

(venv_hjh) D:\AutoTest\Web\Ltc_System_Po\Case>pytest -vs test_sjbs.py --alluredir=./result/ --clean-alluredir
================================================================================= test session starts =================================================================================
platform win32 – Python 3.8.9, pytest-8.1.1, pluggy-1.4.0 – D:\AutoTest\Web\venv_hjh\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\AutoTest\Web\Ltc_System_Po\Case
plugins: allure-pytest-2.13.2, Faker-24.1.0
collecting … log_fun.py
D:\AutoTest\Web\Ltc_System_Po\Page
D:\AutoTest\Web\Ltc_System_Po
D:\AutoTest\Web\Ltc_System_Po\config\conf.yaml
collected 1 item

test_sjbs.py::TestCase::test_sjbs
DevTools listening on ws://127.0.0.1:61486/devtools/browser/84737158-a23e-447b-9f5e-098d7517fca7
ERROR

======================================================================================= ERRORS ========================================================================================
________________________________________________________________________ ERROR at setup of TestCase.test_sjbs _________________________________________________________________________

self = <allure_pytest.listener.AllureListener object at 0x0000018E21942E50>, item =

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_setup(self, item):
    if not self._cache.get(item.nodeid):
        uuid = self._cache.push(item.nodeid)
        test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now())
        self.allure_logger.schedule_test(uuid, test_result)
    yield
  self._update_fixtures_children(item)

…..\venv_hjh\lib\site-packages\allure_pytest\listener.py:102:


…..\venv_hjh\lib\site-packages\allure_pytest\listener.py:71: in _update_fixtures_children
for fixturedef in _test_fixtures(item):


item =

def _test_fixtures(item):
    fixturemanager = item.session._fixturemanager
    fixturedefs = []

    if hasattr(item, "_request") and hasattr(item._request, "fixturenames"):
        for name in item._request.fixturenames:
          fixturedefs_pytest = fixturemanager.getfixturedefs(name, item.nodeid)

E AttributeError: ‘str’ object has no attribute ‘iter_parents’

…..\venv_hjh\lib\site-packages\allure_pytest\listener.py:345: AttributeError
================================================================================== warnings summary ===================================================================================
test_sjbs.py::TestCase::test_sjbs
D:\AutoTest\Web\venv_hjh\lib\site-packages_pytest\runner.py:240: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: allure_listener, Hook: pytest_runtest_setup
AttributeError: ‘str’ object has no attribute ‘iter_parents’
For more information see API Reference — pluggy 0.1.dev137+g2efd28e documentation
lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise

– Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================================================================== short test summary info ===============================================================================
ERROR test_sjbs.py::TestCase::test_sjbs - AttributeError: ‘str’ object has no attribute ‘iter_parents’
============================================================================= 1 warning, 1 error in 7.55s =============================================================================

解决了,貌似是allure-pytest包的问题 重新装了就好了