current position:Home>Build Python project in Jenkins, pychar output is normal and Jenkins output modulenotfounderror: no module named problem

Build Python project in Jenkins, pychar output is normal and Jenkins output modulenotfounderror: no module named problem

2022-05-15 02:37:19Koki can test a rookie

jenkins and python Integration of :
https://www.cnblogs.com/miki-peng/p/14460821.html
One 、 Build a new task , A new task of building a free style
 Insert picture description here
Two 、 Configure the newly created task
 Insert picture description here
3、 ... and 、 Time configuration
 Insert picture description here
Four 、windows Run the code , Click save
 Insert picture description here
5、 ... and 、 structure
 Insert picture description here
6、 ... and 、 View results
 Insert picture description here
7、 ... and 、 Wrong report . In red , Execution success is blue .
 Insert picture description here

8、 ... and 、 The correct code should be :
python
print(‘hello’)

 Insert picture description here

Nine 、 In our execution python In the process of : The code format is generally written like this :
First cd The path to our execution project , Again python + Execute our documents

E:
cd E:\python\project\api_tow\
python unittest_suite.py

 Insert picture description here

in addition : About ,Pycharm Output normal and jenkins Output ModuleNotFoundError: No module named problem :

 Insert picture description here

Need our code front Plus the path : First line position , First line position , First line position , Say important things three times ! It's a pit ! So be sure to put it in the front , Otherwise jenkins The path to the code cannot be found
This is how it is written :

import sys
# This is my executable path :E:\\python\\project ; This is a python Third party download path :D:\\python\\Lib\\site-packages; This is my python Own library path :D:\\python\\Lib ; This is the third-party download path :C:\\Users\\ZF-JS\\AppData\\Roaming\\Python\\Python38\\site-packages; Put it all on , It must be good 
sys.path.append("E:\\python\\project")
sys.path.append("D:\\python\\Lib\\site-packages")
sys.path.append("D:\\python\\Lib")
sys.path.append("C:\\Users\\ZF-JS\\AppData\\Roaming\\Python\\Python38\\site-packages")

#  Then there's your code 
import unittest
import HTMLTestRunner
suite = unittest.TestSuite()
loader = unittest.TestLoader()

Be careful : The execution file should use the superior path , There are many ways to find the superior path , To look good , give an example :

#  The first one is :
import os
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

#  The second kind  
import os
test_case_path = os.path.split(os.path.split(os.path.split(os.path.realpath(__file__))[0])[0])[0]

If not enough, you can add , The straight point is to find the path of our following project :
 Insert picture description here

Come here , Basically, it's OK 了

copyright notice
author[Koki can test a rookie],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/132/202205120517585639.html

Random recommended