[TIP] Does testscenarios employ unittest?

boB Stepp robertvstepp at gmail.com
Sun Sep 25 20:06:26 PDT 2016


On Sun, Sep 25, 2016 at 9:49 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> boB Stepp <robertvstepp at gmail.com> writes:
>
>> I finally figured out how to use testscenarios for the simple problem
>> I am using to start learning TDD.  I was surprised to discover that I
>> did not need to import unittest.
>
> You do need your test case classes to inherit from ‘unittest.TestCase’.
>
> What you may be doing is inheriting your test case classes from some
> other class which *itself* is a subclass of ‘unittest.TestCase’.

The following is what I am using and it appears to work:

=========================================================
from testscenarios import TestWithScenarios

import right_justify

scenario0 = ('string0', {
    'input': "Monty Python",
    'expected_result0': 70})
scenario1 = ('string1', {
    'input': "She's a witch!",
    'expected_result0': 70})
scenario2 = ('string2', {
    'input': "Beware of the rabbit!!!  She is a vicious beast who will rip"
                " your throat out!",
    'expected_result0': 70})

class TestRightJustify(TestWithScenarios):
    '''Tests for the function, "right_justify(a_string)", in the "right_justify
    module".'''

    scenarios = [scenario0, scenario1, scenario2]
# Tests follow...
==========================================================

I am using Python 3.5.2.  Before I installed testscenarios, I first
installed testtools as that was listed as a dependency for
testscenarios.

As you can see, I did not have to explicitly import unittests, so thus
my questions.  So what is actually happening here?

-- 
boB



More information about the testing-in-python mailing list