ModuleNotFoundError:Azure DevOps Selenium Python 中没有名为"POM"的模块



请帮我解决这个bug:我在Azure DevOps上运行自动化测试Selenium Python。我可以在本地机器上运行pass,但在Azure Devops上失败

* * 1。这是错误日志:* *


Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents: shell
pytest -s  ./TestScript/test_smoketest.py --html=pytest_selenium_test_report.html
========================== Starting Command Output ===========================
"C:Windowssystem32cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:a_temp27823a4e-e3d1-4223-9442-76c34c20d6cd.cmd""
============================= test session starts =============================
platform win32 -- Python 3.7.9, pytest-7.2.0, pluggy-1.0.0
rootdir: D:a1s
plugins: azurepipelines-1.0.4, html-3.2.0, metadata-2.0.4, nunit-1.0.3
collected 0 items / 1 error
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
No Result Found to Publish 'D:a1stest-output.xml'.
##[error]1 test(s) failed, 0 test(s) collected.
Skipping uploading of coverage data.
=================================== ERRORS ====================================
________________ ERROR collecting TestScript/test_smoketest.py ________________
ImportError while importing test module 'D:a1sTestScripttest_smoketest.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
c:hostedtoolcachewindowspython3.7.9x64libimportlib__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
TestScripttest_smoketest.py:10: in <module>
from POM.loginPage import Loginpage
E   ModuleNotFoundError: No module named 'POM'
------------- generated Nunit xml file: D:a1stest-output.xml --------------
--- generated html file: file:///D:/a/1/s/pytest_selenium_test_report.html ----
=========================== short test summary info ===========================
ERROR TestScript/test_smoketest.py
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
============================== 1 error in 0.11s ===============================
##[error]Cmd.exe exited with code '2'.

这是我的代码结构:输入图片描述

* * 2。这是azure-pipelines.yml:* *

trigger:
- main
pool:
vmImage: windows-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
architecture: 'x64'
- script: |
python -m pip install --upgrade pip
displayName: 'Instal dependencies'
- script: |
pip install webdriver-manager
pip install selenium
pip install pytest pytest-azurepipelines
pip install pytest-html
set PYTHONPATH
displayName: 'Import libriary'
- script: |    
pytest -s  ./TestScript/test_smoketest.py --html=pytest_selenium_test_report.html
displayName: 'Run test script'

* * 3。这是测试脚本[testrongmoketest.py]* *

import pytest
import pytest_html
import sys
import os
import time
sys.path.append(os.path.join(os.path.dirname(__file__), "...", "..."))
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from POM.loginPage import Loginpage
from POM.profile import Profile
from Setup import settings

@pytest.fixture
def driver():
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(settings.link)
driver.execute_script("localStorage.setItem('accessToken', '{}');".format(settings.accessToken_admin))
time.sleep(2)
driver.refresh()
driver.maximize_window()
yield driver
driver.close()
driver.quit()
print("Complete test case")
def test_login_with_accessToken(driver):
loginPage = Loginpage(driver)
loginPage.wait_for_welcomeBanner()
def test_login_with_SSO(driver):
profile = Profile(driver)    
profile.click_Avartar()
profile.click_Logout()
time.sleep(6)
loginPage = Loginpage(driver)
loginPage.click_SSO()
loginPage.input_email(settings.email)
loginPage.click_remember()
loginPage.click_login()
loginPage.wait_for_welcomeBanner()

我尝试添加init.py到每个文件夹,但仍然不起作用

尝试更改sys.path.append(os.path.join(os.path.dirname(__file__), "...", "..."))

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

最新更新