Skip to main content

A unittest patch that can automaticly ``skip`` test case based on dependence info calculated by ``trace``.

Project description

utknows is a unittest patch that can automaticly skip test case based on dependence info calculated by trace.

Installing

You can install utknows through pip or easy-install:

pip install utknows

Or you can download the latest development version, which may contain new features.

Using utknows

utknows should be used before unittest.main is invoked like this:

from utknows import setup_utknows
setup_utknows(db, db_prefix="utknows", root_dir=os.path.abspath(os.curdir))
unittest.main(******, exit=False)
# some resource release, etc db.close()

The db is a persistence database instance, and implementate __getitem__ and __setitem__ method.

The root_dir is the tracing base of dependence used by trace.

The db_prefix is the key prefix in db.

When the first time tests runs, it calculate all the dependence info of every testcase:

utknows/examples$ python alltests.py
......
----------------------------------------------------------------------
Ran 6 tests in 0.031s
OK

After that, the case will be skipped when the dependence info is satisfacted:

utknows/examples$ python alltests.py
ssssss
----------------------------------------------------------------------
Ran 0 tests in 0.003s

OK (skipped=6)

Case will be rerun after you modify any file it depends:

utknows/examples$ touch test_hello.py
utknows/examples$ python alltests.py
...sss
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK (skipped=3)

The s output here stand for skip.

Examples

Using redis as backend:

import redis

def open_db():
    return redis.Redis(host='localhost', port=6379, db=0)

def close_db(db):
    db.client_kill('localhost:6379')

from utknows import setup_utknows
db = open_db()
setup_utknows(db, root_dir=os.path.abspath(os.curdir))
unittest.main(defaultTest="suite", buffer=True, exit=False)
close_db(db)

Using dbm as backend:

import os
import shelve

def open_db():
    return shelve.open(os.path.join(os.curdir, '.utknows'), writeback=True)

def close_db(db):
    db.sync()
    db.close()

from utknows import setup_utknows
db = open_db()
setup_utknows(db, root_dir=os.path.abspath(os.curdir))
unittest.main(defaultTest="suite", buffer=True, exit=False)
close_db(db)

License

utknows is copyright 2013 mapix and Contributors, and is made available under BSD-style license; see LICENSE for details.

Project details


Download files

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

Source Distribution

utknows-0.1.1.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file utknows-0.1.1.tar.gz.

File metadata

  • Download URL: utknows-0.1.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for utknows-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bc47d1cf8384393813cea495537c8753e984f6386f075d3ac3127ddb9d6f7ccc
MD5 9c9aedf9e61f3079cb7e3985ce1744db
BLAKE2b-256 9d523a9ab3d4b865dad275e750d084ab2f9d5a2fa2d3225757eda45f7743c96f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page