Log In
New Account
Home My Page Project Cloud Code Snippets Project Openings MIN Test Framework
Summary Forums Tracker Lists Tasks Docs News SCM Files Wiki

Using MIN Python scripter


Python module usage in MIN


The following article describes usage of Python scripter module and python-based test cases in MIN.

When using MIN, it is possible to test code written in Python, as well as using python just for purpose of scripting/combining cases written in C/C++.

Basic usage

To use Python - based test cases, user needs to configure MIN to use pythonscripter, with appropriate file containing python - based test cases (for information how to do this, refer to appropriate topics or User Guide). Python test cases can be executed with MIN console UI.

Python test case file syntax

Test Case definition

If file is to be interpreted as test case file, it needs to follow those guidelines:

  • each function with name starting with case_ will be interpreted as MIN test case
  • test case function should return NULL if test case is passed, other value otherwise. If function doesn't have return value, it will be interpreted as failed.
  • inside docstring user can define title of test case which will be seen by MIN. It is not mandatory.
  • to use MIN-specific functionality, script needs to import min_ext module. MIN updates necessary environment variables by itself, so user does not need to worry about it.

min_ext reference


Function prints specified message to MIN console UI. It takes one mandatory argument - string to be printed. Example usage:

 min_ext.Print_to_cui("Printout text")


Function sets MIN event of type indication and specified name. Example usage:



Function sets MIN event of type state and specified name example usage:



Function unsets MIN event of type state and specified name. Note, that only events of type state can be unset. Example of usage:



Function requests event. If test case will be waiting for some event, it first needs to request it. Function takes mandatory parameter - string containing the name of event to be requested, and optional parameter - string state, if the event to be requested is of state type. If second parameter is omitted, or has value different than state, MIN will assume that indication event was requested. Example usage:





Function starts waiting for previously requested event. Function should not return until awaited event is received. Function takes one mandatory argument: name of event. Example usage:



Function executes test case from other MIN test module. Function does not return until started test case finishes execution. Function takes the following arguments:

  • Name of test module
  • Name of test case file (optional, can be omitted)
  • Name of test case

All parameters are strings, and should be specified in order given above. Example usage:



Function starts asynchronous execution of test case from some other module. Note that Python test case won't end until this test case finishes, but result of test case is not provided. It is possible to synchronize with this test case via events. Function takes the following parameters:

  • Name of test module
  • Name of test case file (optional, can be omitted)
  • Name of test case

All parameters are strings, and should be specified in order given above. Example usage:





Function creates MIN logger structure (Keep in mind, that the logger created in test case has to be destroyed in the same case, otherwise there will be resource leak). It takes the following arguments (all mandatory):

  • Name of directory in which log will be stored
  • Name of log file
  • Format information (can be "txt" or "html")

Function returns int that acts as a handle to logger (needed for further log operations). Example usage:

 My_logger = min_ext.Create_logger("/tmp","logfile.log","html")


 My_txt_logger = min_ext.Create_logger("/tmp","logfile.log","txt")


Function writes specified log message to log. Function takes the following arguments.

  • Handle to logger (returned by Create_logger)
  • Style (can be b/B for bold, u/U for underline and i/I for italic. Other values are ignored.). Styles work of course only in case of html logger. Can be omitted.
  • Text to be logged

Example usage:

 min_ext.Log(My_logger,"b","log this text")


 min_ext.Log(My_txt_logger,"log this text")


Function used to "destroy" previously created logger, should be used to prevent resource leaks. As an argument it takes handle to logger. Example usage:


PyUnit? cases wrapper

With MIN python module package comes wrapper file for PyUnit? test cases. It might be convenient when moving test development from PyUnit? to MIN - so user is still able to execute already developed PyUnit? cases under control of MIN (console interface). Template file, minwrap.py can be found under ''/min_py_module/min_ext/". To use it, following actions are required:

  • template needs to be edited, and all occurences of PyUnit?_module_xxx need to be replaced by name of Python module containing PyUnit? test cases. Note that it must be possible to import modules, so PyUnit? module should be placed in directory defined in PYTHONPATH environment variable; the altered template should be placed in directory defined as MIN's "ModSearchPath?".
  • py_moduleTestModule should be configured with altered template as test case file.

SUT Python extension

To use Python as language for scripting C/C++ based tests, user should contain code he wants to test (or calls to it) inside python extension, further called SUT extension (SUT stands for "system under test"). For basics of creation of python extensions refer to available Python documentation. MIN releases provide template C file for generating such extension, along with Python build script for it(sut_ext.c & setup.py can be found under : /min/TestModuleTemplates?/sut_extXXX).

Example MIN Python testcase

 import min_ext
 import sut_module1
 def case_ms1():
        retval = min_ext.Wait_event("ping")
        if (retval == 0):
                retval = sut_module1.Do_stuff()
        return retval

(last edited January 5, 2009) - Read Only [info] [diff])
FindPage by browsing or searching
5 best incoming links: FrontPage (22), RecentChanges (11)
5 best outgoing links: FrontPage (22)ModSearchPath (2)MyEvent (2)MyEventInd (2)MyEventState (2)
5 most popular nearby: FrontPage (2648), RecentChanges (303), MyEvent (171), MyEventInd (141), MyEventState (141)

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment