# Upload custom test case guidelines

Once a test case is uploaded to the platform, the platform decompresses the zip package and uses Python's built-in inspect module to analyze the test function name starting withtest.

During the inspect process, each Python file is executed, and analysis failure may occur due to improper case directory structure.

Two use case directory organizational structures 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 the test_a.py, test_b.py, and util directories to package and compress into case.zip

___my_case
   |___test_pack
        |___ __init__.py   // 注意这里,加上__init__.py使整个test_pack成为一个包
        |___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 to compress to case.zip

Note: above two ways, do not directly select "my_case" this layer of directory compression!!!

# Local debugging

Download the script to assist in debug when problems occur

cd ${your_path}/local_script

python3 debug_analyse.py -d ${your_case_path}

Reference examples:

cd /leviwu/test/local_script
python3 debug_analyse.py -d /leviwu/minitest-case/user_case/my_case

If the console has standard output, the case analysis is successful

Common mistakes are as follows:

  1. ValueError: source code string cannot contain null bytes Please make sure the file is UTF-8 encoded

# Use cases require additional third-party library files

At present, cloud testing services have installed commonly used third-party libraries, such asdateutil``xlwt``xlrd``pandas``nose``pandas,But not all third-party libraries can be covered. If the use case parsing appearsModuleNotFoundError, ImportErrorSimilar errors typically occur when a third-party library file is used in a use case, and the third-parties library needs to be uploaded as well.

In particular, it is strongly recommended to install onLinuxorMac.Because cloud testing services and real-world testing are in the Linux environment, many third-party libraries have different versions for different platforms (Win, Mac, Linux), and the packages installed under Windows cannot be resolved when uploaded under Linux.

The following tofaker(note: faker Kuyun test has been installed, here is only used for example) library as an example, in the cloud test using the specific steps as follows:

# 1. Install the third-party library under the minitest_lib folder

Pip support allows libraries to be installed under the specified document folder, which in cloud testing is uniformly placed under theminitest_libdocument folder.Please note that the cloud test service only recognizes theminitest_libdocument folder, other document folders do not recognize!

In the case of faker, perform the installation in the directory of case. Refer to the command as follows:

 # 注意只需要将faker替换成你需要的库,其他参数保留
 pip3 install faker -t minitest_lib -I --no-deps
 
 # 参数解释:
 # -t: 指定路径,此处必须为 minitest_lib
 # --no-deps: 不安装库的依赖包

# 2. Debugging with debug_analyse.py

After installing the library files, debug the case with the debug_analyse.py script in local debugging. Common error situations are as follows:

  • If there are errors such as ModuleNotFoundError, it means that there are other dependent library files that are not installed, and you need to continue to install the corresponding library files
  • In the code of the test case, if you want to reference a third-party library file, just reference it directly, such asimport faker.from minitest_lib import faker

# 3. Upload to cloud testing and debug again

After the local debugging is successful, upload the use case to the cloud testing service. If there are still errors reported, check:

  • Some libraries may already be installed in the local python3 environment, and at this time it will execute successfully in debug_analyse.py, but the upload cloud is wrong.For example, dateutil has been installed locally, but the cloud test is not installed, and the upload will continue to report errorsModuleNotFoundError: No module named 'dateutil',At this point, you need to install datetutil as well, such as executingpip3 install python-dateutil-t minitest_lib --no-deps -I
  • Some particularly complex library files also require a binary file to be installed in order to be used, which CloudWatch does not support
  • Again, try to install packages and debug scripts inlinuxorMacenvironment.This is consistent with the cloud test environment, avoiding the installation package environment or character encoding errors in the window environment

If there are errors, please join the cloud test service official enterprise micro group, contact MiniTest assistant feedback

# I need help.