Error while running parameterised tests

44 views
Skip to first unread message

akshaym...@gmail.com

unread,
Sep 3, 2020, 6:30:25 AM9/3/20
to lemoncheesecake
lemoncheesecake version 1.5.2
Python 3.8.5

Code:

# test_data.json

[
  {
    "source": [0, 0],
    "destination": [1, 1],
    "expect_success": true
  }
]

# my_test.py (imports removed)

def naming_scheme(name, description, parameters, idx):
    source = str(parameters["source"])
    destination = str(parameters["destination"])
    expect_success = str(parameters["expect_success"])
    return "%s_%s_%s" % (name, source, destination), \
           "Check the functionality works with " \
           "source {} and destination {} with success={}".format(source, destination, expect_success)


@lcc.suite(description="My tests", rank=1)
class MyTests:
    PROJECT_DIR = os.path.join(os.path.dirname(__file__), 'resources')

    @lcc.test("verify xyz functionality")
    @lcc.parametrized(json.load(open(os.path.join(PROJECT_DIR, "test_data.json"))), naming_scheme)
    def verify_xyz(self, source, destination, expect_success):
        source_location = Location(source[0], source[1])
        destination_location = Location(destination[0], destination[1])
        # more test code here

On triggering the tests, lcc command line tool throws below error:

A test with name 'wrapper' is already registered in test suite MyTests

Am I missing anything or is this a bug in lcc?

akshaym...@gmail.com

unread,
Sep 3, 2020, 6:55:01 AM9/3/20
to lemoncheesecake
If I tweak the lcc source code (suite/core.py line number 123) to below, then I do not see the issue and the tests are run for multiple data sets too (from test_data.json).

if test.name != 'wrapper' and test.name in self._test_names:

However, I'm not sure if that's a proper fix and that whether it would have any side effects.

Nicolas Delon

unread,
Sep 6, 2020, 8:57:59 AM9/6/20
to lemoncheesecake
Hello,

I took your source code but I could not reproduce the error you described. Don't you have other tests in your project that could trigger this issue ?

Best regards,

Nicolas.

Nicolas Delon

unread,
Sep 6, 2020, 9:36:12 AM9/6/20
to lemoncheesecake
That's strange. No, I don't have any other tests to check this. Any idea as to what could be causing this?

=> Are you really sure you can reproduce your own issue with the example you provided ? I guess you did some changes between your real code and your example here, try to figure out the differences.

akshaym...@gmail.com

unread,
Sep 6, 2020, 9:41:23 AM9/6/20
to lemoncheesecake
Yes, in fact, I forgot to add the setup_suite() function in this code example. Thanks for pointing that out.

It looks like this:

    def setup_test(self, test):
         # some setup code here


Nicolas Delon

unread,
Sep 6, 2020, 9:45:54 AM9/6/20
to lemoncheesecake
Even when adding a setup_test method in the class, I'm not able to reproduce the issue.

akshaym...@gmail.com

unread,
Sep 6, 2020, 9:48:23 AM9/6/20
to lemoncheesecake
Okay, even I'm unable to replicate the issue now. This is weird. :/

In order to ensure none of my changes in the source code are present, I did an uninstall and install of lemoncheesecake using pip, but I cannot replicate the issue.

Nicolas Delon

unread,
Sep 6, 2020, 9:53:19 AM9/6/20
to lemoncheesecake
Ok 👍

akshaym...@gmail.com

unread,
Sep 6, 2020, 10:12:04 AM9/6/20
to lemoncheesecake
Sorry Nicolas to bother you with this issue.

I assume I was doing something wrongly earlier, so I'll try to figure it out if at all I see it again.

Thank you.

Reply all
Reply to author
Forward
0 new messages