测试人社区

pipeline运行ui自动化测试,出现模块导入错误

##在jenkins日志报错结果
“”"
============================= test session starts ==============================
platform linux – Python 3.8.0, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 – /usr/local/python3.8.0/bin/python3.8
cachedir: .pytest_cache
rootdir: /home/lx/jenkins_home/workspace/test_xueqiu
plugins: allure-pytest-2.8.18
collecting … collected 0 items / 1 error

==================================== ERRORS ====================================
___________________ ERROR collecting testcases/test_login.py ___________________
ImportError while importing test module ‘/home/lx/jenkins_home/workspace/test_xueqiu/testcases/test_login.py’.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/python3.8.0/lib/python3.8/importlib/init.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
test_login.py:1: in
from page.App import App
E ModuleNotFoundError: No module named ‘page’
=========================== short test summary info ============================
ERROR test_login.py
!!! Interrupted: 1 error during collection !!!
=============================== 1 error in 0.09s ===============================
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE
“”"

##我在本机上是可以跑通的,不存在网上说的导入模块互相依赖的状况,所以不知道哪里的问题

目测是模块路径问题导致导入错误
代码中可以使用os.path模块获取相对路径
相关知识:Python os.path() 模块