封装的scrcpy录屏方法在本地可以运行,在Jenkins上运行报错

把scrcpy录屏方法封装在conftest.py文件里,在本地直接运行可以成功,但是放在jenkins上运行报错
Jenkins报错信息:

______________________ ERROR at setup of Test001.test002 ______________________

    @pytest.fixture(scope="class", autouse=True)
    def record():
        cmd = shlex.split("scrcpy --record mp.mp4")
>       p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

conftest.py:14: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
D:\python\python36\lib\subprocess.py:709: in __init__
    restore_signals, start_new_session)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <subprocess.Popen object at 0x000002347B29C198>
args = 'scrcpy --record mp.mp4', executable = None, preexec_fn = None
close_fds = False, pass_fds = (), cwd = None, env = None
startupinfo = <subprocess.STARTUPINFO object at 0x000002347B29C0B8>
creationflags = 0, shell = False, p2cread = Handle(604), p2cwrite = -1
c2pread = 11, c2pwrite = Handle(780), errread = -1, errwrite = Handle(768)
unused_restore_signals = True, unused_start_new_session = False

    def _execute_child(self, args, executable, preexec_fn, close_fds,
                       pass_fds, cwd, env,
                       startupinfo, creationflags, shell,
                       p2cread, p2cwrite,
                       c2pread, c2pwrite,
                       errread, errwrite,
                       unused_restore_signals, unused_start_new_session):
        """Execute program (MS Windows version)"""
    
        assert not pass_fds, "pass_fds not supported on Windows."
    
        if not isinstance(args, str):
            args = list2cmdline(args)
    
        # Process startup details
        if startupinfo is None:
            startupinfo = STARTUPINFO()
        if -1 not in (p2cread, c2pwrite, errwrite):
            startupinfo.dwFlags |= _winapi.STARTF_USESTDHANDLES
            startupinfo.hStdInput = p2cread
            startupinfo.hStdOutput = c2pwrite
            startupinfo.hStdError = errwrite
    
        if shell:
            startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = _winapi.SW_HIDE
            comspec = os.environ.get("COMSPEC", "cmd.exe")
            args = '{} /c "{}"'.format (comspec, args)
    
        # Start the process
        try:
            hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                                     # no special security
                                     None, None,
                                     int(not close_fds),
                                     creationflags,
                                     env,
                                     os.fspath(cwd) if cwd is not None else None,
>                                    startupinfo)
E                                    FileNotFoundError: [WinError 2] The system cannot find the file specified

scrcpy录屏方法封装:

@pytest.fixture(scope="class", autouse=True)
def record():
    cmd = shlex.split("scrcpy --record mp.mp4")
    p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    yield
    #os.kill(p.pid, signal.CTRL_C_EVENT)
    # os.popen('taskkill.exe/pid:'+str(p.pid))
    os.kill(p.pid, signal.SIGTERM)

    sleep(1)
    with open("mp.mp4", "rb") as f:
        content = f.read()
    allure.attach(content, attachment_type=allure.attachment_type.MP4)

请老师帮忙查看下是哪里的问题,如何在Jenkins上成功运行,谢谢

感觉试试看shell=True

改成shell=True之后case可以运行,但是录屏还是会报错,之前shell=False时,case都运行不了

录屏还是那个文件找不到的错误吗

不是了,这次错误是拒绝访问

___________________ ERROR at teardown of Test001.test002 _____________________

self = <allure_commons._allure.fixture object at 0x000001C0A38F4160>, args = ()
kwargs = {}

    def __call__(self, *args, **kwargs):
        self.parameters = func_parameters(self._fixture_function, *args, **kwargs)
    
        with self:
>           return self._fixture_function(*args, **kwargs)

..\venv\lib\site-packages\allure_commons\_allure.py:185: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @pytest.fixture(scope="class", autouse=True)
    def record():
        cmd = shlex.split("scrcpy --record mp.mp4")
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        yield
        #os.kill(p.pid, signal.CTRL_C_EVENT)
        # os.popen('taskkill.exe/pid:'+str(p.pid))
>       os.kill(p.pid, signal.SIGTERM)
E       PermissionError: [WinError 5] Access is denied

conftest.py:18: PermissionError

你看看你那里有没有生成mp.mp4,这个权限问题是你杀进程,没有权限,可以有其他办法解决

我这边在workspace生成.mp4文件,但是打不开

没有生成mp.mp4,就在本地运行的时候可以看到scrcpy打开了,但是用Jenkins运行,scrcpy没有打开

就是用Jenkins运行的时候,没有生成.mp4的文件,但它可以把我本地原有的.mp4文件放进allure报告里,感觉就是放到Jenkins运行的时候scrcpy这个录屏用的软件打不开

打开文件前,加个sleep

没听懂 生成的是文件 怎么sleep