jeudi 29 octobre 2020

Cmd.exe exited with code '5' on Azure DevOps when multiple python test scripts runs in one go

I'm trying to execute multiple python scripts within Azure DevOps pipeline but the "##[error]Cmd.exe exited with code '5'." is returned with no identification of any testcase apparently.

In the "execute script" step of the pipeline, the following command has been written:

 "C:\Program Files\Python\Python38\python.exe"  -m pytest $(System.DefaultWorkingDirectory)\autotest_main.py -v --junitxml=test-results.xml --html=report.html --self-contained-html

and this works fine untile the script "autotest_main.py" contains just the suite with the test cases. But I need to organize a lot of test cases, so the starting point is the autotest.py script that is written as follows:

import os

os.system('test_Preconditions.py')
os.system('test_Suite1.py')
os.system('test_Suite2.py')
os.system('test_Suite3.py')
os.system('test_Suite4.py')

I also used the test_ notation to make the testcases easy to be identified. Each of the test_Suite1.py file contains than the unit tests in conjunction with selenium webdriver to test the frontend of a web application. When I run the script on the local machine everything works fine but when I run it using azure devops the "##[error]Cmd.exe exited with code '5'." is returned. Here the log:

##[section]Starting: execute script
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.176.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
"C:\Program Files\Python\Python38\python.exe"  -m pytest C:\agent\_work\12\s\autotest_main.py -v --junitxml=test-results.xml --html=report.html --self-contained-html
========================== Starting Command Output ===========================
##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\agent\_work\_temp\b653526f-53a0-4ac7-8a22-50698ed4ba58.cmd""
============================= test session starts =============================
platform win32 -- Python 3.8.3, pytest-6.1.0, py-1.9.0, pluggy-0.13.1 -- C:\Program Files\Python\Python38\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.8.3', 'Platform': 'Windows-10-10.0.14393-SP0', 'Packages': {'pytest': '6.1.0', 'py': '1.9.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.1.1', 'metadata': '1.10.0', 'nunit': '0.6.0'}}
rootdir: C:\agent\_work\12\s
plugins: html-2.1.1, metadata-1.10.0, nunit-0.6.0
collecting ... collected 0 items
 
---------- generated xml file: C:\agent\_work\12\s\test-results.xml -----------
--------- generated html file: file://C:\agent\_work\12\s\report.html ---------
============================ no tests ran in 0.32s ============================
##[error]Cmd.exe exited with code '5'.
##[section]Finishing: execute script

Any suggestion to fix this problem? I want to possibly prevent to write a lot of execute script steps within the Azure Pipeline if possible.

Aucun commentaire:

Enregistrer un commentaire