Skip to content

Latest commit

 

History

History
169 lines (109 loc) · 4.34 KB

unittest-support.rst

File metadata and controls

169 lines (109 loc) · 4.34 KB

datatest

Unittest Support

Datatest can be used together with the unittest package from the Python Standard Library. For a quick introduction, see:

  • Automated Data Testing: Unittest <unittest-intro-docs>
  • Unittest Samples <unittest-samples-docs>

DataTestCase

DataTestCase

VALIDATION METHODS

The assertion methods wrap validate and its methods:

from datatest import DataTestCase

class MyTest(DataTestCase):
    def test_mydata(self):
        data = ...
        requirement = ...
        self.assertValid(data, requirement)

assertValid

assertValidPredicate

assertValidRegex

assertValidApprox

assertValidFuzzy

assertValidInterval

assertValidSet

assertValidSubset

assertValidSuperset

assertValidUnique

assertValidOrder

ACCEPTANCE METHODS

The acceptance methods wrap accepted and its methods:

from datatest import DataTestCase

class MyTest(DataTestCase):
    def test_mydata(self):
        data = ...
        requirement = ...
        with self.accepted(Missing):
            self.assertValid(data, requirement)

accepted

acceptedKeys

acceptedArgs

acceptedTolerance(tolerance, /, msg=None) acceptedTolerance(lower, upper, msg=None)

Wrapper for accepted.tolerance.

acceptedPercent(tolerance, /, msg=None) acceptedPercent(lower, upper, msg=None)

Wrapper for accepted.percent.

acceptedFuzzy

acceptedCount

Command-Line Interface

The datatest module can be used from the command line just like unittest. To run the program with test discovery use the following command:

python -m datatest

Run tests from specific modules, classes, or individual methods with:

python -m datatest test_module1 test_module2
python -m datatest test_module.TestClass
python -m datatest test_module.TestClass.test_method

The syntax and command-line options (-f, -v, etc.) are the same as unittest---see unittest's command-line documentation for full details.

Note

Tests are ordered by file name and then by line number (within each file) when running datatest from the command-line.

Test Runner Program

DataTestRunner

DataTestProgram(module='__main__', defaultTest=None, argv=None, testRunner=datatest.DataTestRunner, testLoader=unittest.TestLoader, exit=True, verbosity=1, failfast=None, catchbreak=None, buffer=None, warnings=None)

main