After test cases are uploaded to the platform, the platform unpacks the zip package and uses Python's built-in inspect module to analyze test function names starting with test.
During the inspect process, each Python file is executed once. If the case directory structure is not organized properly, this may result in analysis failures.
Recommended Directory Structure
Two directory organization structures for use cases are recommended:
①
___my_case
|___test_a.py // from util.base import xxxx
|___test_b.py // from util.base import xxxx
|___util
|___ __init__.py
|___base.py
Select test_a.py, test_b.py, and the util directory, then package and compress them into case.zip
②
___my_case
|___test_pack
|___ __init__.py // Note: Add __init__.py to make the entire test_pack a package
|___test_a.py // from test_pack.util.base import xxxx
|___test_b.py // from test_pack.util.base import xxxx
|___util
|___ __init__.py
|___base.py
Select the test_pack directory and compress it into case.zip
Note: For both of the above methods, do not directly select the "my_case" directory level for compression!!!
Local Debugging
If issues arise, you can download the script to assist with debugging.
cd ${your_path}/local_script
python3 debug_analyse.py -d ${your_case_path}
Reference example:
cd /leviwu/test/local_script
python3 debug_analyse.py -d /leviwu/minitest-case/user_case/my_case
If the console displays standard output, it indicates that the case analysis was successful.
Common errors include:
- ValueError: source code string cannot contain null bytes Please ensure the file is encoded in UTF-8.
Third-Party Library Files Required for Test Cases
The Cloud Test service has pre-installed common third-party libraries, such as dateutil, xlwt, xlrd, pandas, nose, and pandas. However, these may not cover all third-party libraries. If parsing a test case results in errors like ModuleNotFoundError or ImportError, it typically indicates that the test case relies on a third-party library that is not pre-installed. In such cases, you must upload the required third-party library files.
Please note: It is strongly recommended to install libraries in a Linux or Mac environment. Since both the Cloud Test service and real-device testing run in a Linux environment, many third-party libraries have platform-specific versions (Windows, Mac, Linux). Packages installed on Windows may fail to resolve when uploaded to a Linux environment.
The following steps demonstrate how to use the faker library in Cloud Test (Note: The faker library is already installed in Cloud Test; it is used here solely as an example):
1. Install third-party libraries in the minitest_lib folder
pip supports installing libraries to a specified folder. In cloud testing, all libraries are uniformly placed in the minitest_lib folder. Please note that the cloud testing service only recognizes the minitest_lib folder; other folders are not recognized!
Taking faker as an example, run the installation in the case directory. The reference command is as follows:
# Note: You only need to replace 'faker' with the library you require; keep the other parameters as they are.
pip3 install faker -t minitest_lib -I --no-deps
# Parameter explanation:
# -t: Specifies the path; this must be minitest_lib.
# --no-deps: Do not install the library's dependencies.
2. Debugging with debug_analyse.py
After installing the library files, use the debug_analyse.py script in local debugging to debug test cases. Common error scenarios are as follows:
- If you still encounter errors like ModuleNotFoundError, it indicates that other dependent library files have not been installed. You need to continue installing the corresponding library files.
- In test case code, if you need to reference third-party library files, you can import them directly (e.g.,
import faker), rather than usingfrom minitest_lib import faker.
3. Upload to Cloud Testing and Debug Again
After successful local debugging, upload the test cases to the Cloud Testing service. If errors still occur, please check the following:
- Some libraries might already be installed in your local Python 3 environment, allowing them to execute successfully in
debug_analyse.pylocally, yet causing errors when uploaded to Cloud Testing. For example, ifdateutilis installed locally but not in Cloud Testing, you will encounter aModuleNotFoundError: No module named 'dateutil'error upon upload. In this case, simply installdateutilas well, for example by runningpip3 install python-dateutil -t minitest_lib --no-deps -I - Some highly complex libraries require binary files to function, which are not supported by Cloud Testing
- Reminder: It is strongly recommended to install packages and debug scripts in a
linuxorMacenvironment. This ensures consistency with the Cloud Testing environment and avoids potential package installation or character encoding errors associated with the Windows environment
If errors persist, please join the official Enterprise WeChat group for the Cloud Testing service and contact the MiniTest assistant to report the issue.