Skip to content

Conversation

steveli777
Copy link

To support class level setUp and Teardown for Unittest

@andrewleech
Copy link
Contributor

andrewleech commented Apr 5, 2022

Hi @steveli777 thanks for the contribution! As a general rule (not yet documented anywhere easy to find) the commits here should follow a pattern of module: Change description., for example take a look at the commits in https://github.com/micropython/micropython-lib/pull/488/commits

set_up = getattr(o, "setUp", lambda: None)
tear_down = getattr(o, "tearDown", lambda: None)

if set_up_class:
set_up_class()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the getattr line above, if the function doesn't exist it defaults to lambda: None. This is done so that you don't need the if set_up_class here, you can just run set_up_class() and if it doesn't exist it'll just run the no-op lambda function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, fixed.

except SkipTest as e:
print(" skipped:", e.args[0])
print(" SKIPPED:", e.args[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These output format changes should be done in a separate commit - but only if the new format matches cpython unittest? I'd prefer to add this commit after the #488 changeset which has had some other changes made to the output format already to more closely match cpython.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I reverted those text changes.

Add setUpClass and tearDownClass
Copy link
Contributor

@mattytrentini mattytrentini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean and simple, nice!

@andrewleech
Copy link
Contributor

Hi @steveli777 as I've got a running unittest PR on the go, I've rebased your commit here on top of that one.

It needed some manual intervention to deal with merge conflicts, but I think I got it right: 23866f3

Even with the merge changes the commit is still comitted in your name, I hope that's good for you!

If you get a chance could you review / test this setUpClass functionality in the branch from #488 ?

Otherwise do you have a simple test case I can run (or add as unit test) to cover this functionality?

@dpgeorge
Copy link
Member

dpgeorge commented Oct 4, 2022

This feature was implemented in 2d61dbd

@dpgeorge dpgeorge closed this Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants