A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-February/097611.html below:

[Python-Dev] setUpClass and setUpModule in unittest

[Python-Dev] setUpClass and setUpModule in unittest [Python-Dev] setUpClass and setUpModule in unittestAntoine Pitrou solipsis at pitrou.net
Thu Feb 11 19:58:11 CET 2010
Le Thu, 11 Feb 2010 10:56:32 -0500, R. David Murray a écrit :
> 
> @unittest.case_context(foo_cm)
> @unittest.test_context(foo_test_cm)
> class TestFoo(unittest.TestCase):
> 
>     def test_bar:
>         foo = Foo(self.baz, testing=True)
>         self.assertTrue("Context managers are cool")
> 
> would be easier to write, be more maintainable, and be easier to
> understand when reading the code than the equivalent setUp and tearDown
> methods would be.

I don't think it would be seriously easier to write, more maintainable or 
easier to understand. There's nothing complicated or obscure in setUp and 
tearDown methods (the only annoying thing being PEP8 non-compliance).

As a matter of fact, nose has a "with_setup()" decorator which allows to 
avoid writing setUp/tearDown methods. But in my experience it's more 
annoying to use because:
- you have to add the decorator explicitly (setUp/tearDown is always
  invoked)
- you have to create your own recipient for local state (setUp/tearDown
  can simply use the TestCase instance), or use global variables which 
  is ugly.

Regards

Antoine.

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4