Replacing nose2 Usage within AaC - DevOps-MBSE/AaC GitHub Wiki

There are currently few remnants of nose2 within AaC. Most of these remnants are documentation or otherwise non-executable.

The primary remnant, located in AaC/python/tests/test_aac/in_out/test_paths.py, was recently reworked. An instance of the nose2 parametrization (‘@params’ and a paired ‘import params’) was reworked in a straightforward manner. This reworked code could be reworked again to utilize the pytest pytest.mark.parametrize decorator as described here https://docs.pytest.org/en/latest/how-to/parametrize.html.

An example of pytest parametrization which I found on stack overflow and ran can be found here: https://stackoverflow.com/questions/32899/how-do-you-generate-dynamic-parameterized-unit-tests-in-python. It looks like this:

from parameterized import parameterized

class TestSequence(unittest.TestCase):


    @parameterized.expand([
        ["foo", "a", "a",],
        ["bar", "a", "b"],
        ["lee", "b", "b"],
    ])
    def test_sequence(self, name, a, b):

        self.assertEqual(a,b)

Which will generate the tests:

test_sequence_0_foo (__main__.TestSequence) ... ok

test_sequence_1_bar (__main__.TestSequence) ... FAIL

test_sequence_2_lee (__main__.TestSequence) ... ok

======================================================================

FAIL: test_sequence_1_bar (__main__.TestSequence)

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/usr/local/lib/python2.7/site-packages/parameterized/parameterized.py", line 233, in <lambda>

    standalone_func = lambda *a: func(*(a + p.args), **p.kwargs)

  File "x.py", line 12, in test_sequence

    self.assertEqual(a,b)

AssertionError: 'a' != 'b'

A further productive feature of nose2, which may not be noticeable in the codebase itself, is the ability to automatically locate tests and run then. Given that pytest has this ability and the AaC tests are already written and named in a manner which allows pytest to find and run them, this is not a feature of nose2 which needs to be retained.

A key feature of nose2 which does not seem applicable to AaC is parallel testing. If this feature is needed in the feature by AaC, consideration should be given to using pytest-xdist.

⚠️ **GitHub.com Fallback** ⚠️