Skip to main content

A lightweight unittest extension providing test suites config, concurrent tests, Html/XUnit reports, and data driven utility.

Project description


unishark extends unittest (to be more accurate, unittest2) in the following ways:

  • Customizing test suites with dictionary config (or yaml/json like config).
  • Running the tests concurrently.
  • Generating polished test reports in HTML/XUnit formats.
  • Offering data-driven decorator to accelerate tests writing.

For existing unittests, the first three features could be gained immediately with a single config, without changing any test code.

The Test Config

Here is an example config in YAML format (you could also write it directly in a dict()):

    max_workers: 6
        granularity: module
        modules: [test_module1, test_module2]
        except_classes: [test_module2.MyTestClass3]
        except_methods: [test_module1.MyTestClass1.test_1]
        granularity: class
        disable: False
        classes: [test_module3.MyTestClass5]
        except_methods: [test_module3.MyTestClass5.test_11]
    max_workers: 2
        granularity: method
        methods: [test_module3.MyTestClass6.test_13, test_module3.MyTestClass7.test_15]
        granularity: package
        pattern: '(\w+\.){2}test\w*'
        except_modules: [module1, module2]
        except_classes: [module3.Class1, module3.Class3]
        except_methods: [module3.Class2.test_1, module4.Class2.test_5]
    class: unishark.HtmlReporter
      dest: logs
      overview_title: 'Example Report'
      overview_description: 'This is an example report'
    class: unishark.XUnitReporter
      summary_title: 'Example Report'

  suites: [my_suite_name_1, my_suite_name_2, my_suite_name_3]
  max_workers: 3
  reporters: [html, xunit]
  name_pattern: '^test\w*'

It defines 3 test suites with some of the test cases excluded, and configures running the defined set of tests with multi-threads (max_workers), and generating both HTML and XUnit (default JUnit) format reports at the end of tests.

To run it, simply add the following code:

import unishark
import yaml

if __name__ == '__main__':
    with open('your_yaml_config_file', 'r') as f:
        dict_conf = yaml.load(  # use a 3rd party yaml parser, e.g., PyYAML
        program = unishark.DefaultTestProgram(dict_conf)

A HTML report example can be found Here.

Data Driven

Here are some effects of using @unishark.data_driven.

‘Json’ style data-driven:

@unishark.data_driven(*[{'userid': 1, 'passwd': 'abc'}, {'userid': 2, 'passwd': 'def'}])
def test_data_driven(self, **param):
    print('userid: %d, passwd: %s' % (param['userid'], param['passwd']))


userid: 1, passwd: abc
userid: 2, passwd: def

‘Args’ style data-driven:

@unishark.data_driven(userid=[1, 2, 3, 4], passwd=['a', 'b', 'c', 'd'])
def test_data_driven(self, **param):
    print('userid: %d, passwd: %s' % (param['userid'], param['passwd']))


userid: 1, passwd: a
userid: 2, passwd: b
userid: 3, passwd: c
userid: 4, passwd: d

Cross-multiply data-driven:

def test_data_driven(self, **param):
    l = param['left']
    r = param['right']
    print('%d x %d = %d' % (l, r, l * r))


0 x 1 = 0
0 x 2 = 0
1 x 0 = 0
1 x 1 = 1
1 x 2 = 2
9 x 8 = 72
9 x 9 = 81

You can get the permutations (with repetition) of the parameters values by doing:


Multi-threads data-driven in ‘json style’:

@unishark.multi_threading_data_driven(2, *[{'userid': 1, 'passwd': 'abc'}, {'userid': 2, 'passwd': 'def'}])
def test_data_driven(self, **param):
    print('userid: %d, passwd: %s' % (param['userid'], param['passwd']))

Results: same results as using unishark.data_driven, but up to 2 threads are spawned, each running the test with a set of inputs (userid, passwd).

Multi-threads data-driven in ‘args style’:

@unishark.multi_threading_data_driven(5, time=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
def test_data_driven(self, **param):

Results: 5 threads are spawned to run the test with 10 sets of inputs concurrently (only sleep 1 sec in each thread). It takes about 2 sec in total (10 sec if using unishark.data_driven) to run.

For more information please visit the Project_Home and read


0.2.2 (2015-08-12)

  • support loading tests from a package with pattern matching, and excluding modules/classes/methods from the loaded tests.
  • add load_tests_from_package and load_tests_from_modules api.
  • rename load_test_from_dict to load_tests_from_dict.
  • fix that verbose stdout mode does not print test method doc string.
  • fix that tests loaded with method granularity are not filtered by method name pattern.
  • less strict dependency versions.

0.2.1 (2015-05-11)

  • support data-driven with multi-threads.

0.2.0 (2015-04-04)

  • support running tests in parallel.
  • support configuring test suites, test reporters and concurrent tests in a single dict/yaml config.
  • improve HtmlReporter and XUnitReporter classes to be thread-safe.
  • allow user to generate reports with their own report templates.
  • allow user to filter loaded test cases by setting method name prefix in the test config.
  • bugs fix.
  • improve documentation.

0.1.2 (2015-03-25)

  • hotfix for (broken auto-downloading dependencies)
  • bugs fix.

0.1.1 (2015-03-24)

  • support loading customized test suites.
  • support a thread-safe string io buffer to buffer logging stream during the test running.
  • support writing logs, exceptions into generated HTML/XUnit reports.
  • offer a data-driven decorator.
  • initial setup (documentation,, travis CI, coveralls, etc.).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for unishark, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size unishark-0.2.2.tar.gz (20.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page