Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1981 (closed enhancement: fixed)

Opened 11 years ago

Last modified 10 years ago

Reset turbogears.config on DBTest:setUp()

Reported by: kvdb Owned by: kskuhlman
Priority: normal Milestone: 1.1
Component: Tests Version: 1.1 HEAD
Severity: normal Keywords: testutil
Cc:

Description (last modified by Chris Arndt) (diff)

I've created several unittests for a project and their fail/pass depends on their order. That's because config.update() has a global effect on the test. It would be nice if the config would be reset to the initial state after each test. cherrypy/config.py has a reset() for example. Would that be useful for adding in testutil?

from turbogears import config
from turbogears.testutil import DBTest

class TestA(DBTest):
    def setUp(self):
        testutil.DBTest.setUp(self)

    def test_a(self):
        config.update({'what.ever' : 'foo'})

    def test_b(self):
        # in this test, config.get('what.ever') is already 
        # set to foo, thus affecting this test

Attachments

1981.diff Download (2.6 KB) - added by kskuhlman 10 years ago.
Automatic config reset for testutil.TGTest

Change History

comment:1 Changed 11 years ago by Chris Arndt

  • Type changed from defect to enhancement

The pattern used in TG's own test is usually the following:

def test_foo(self):
    old_setting = config.get('foo')
    config.update({'foo': 'bar'})
    response = self.app.get('/blah')
    config.update({'foo': old_setting})
    assert response == 'spamm'

... which, of course, can become cumbersome for many tests. webtest.TestApp already has a reset() method (currently only deletes cookies). Maybe we could augment this or add a reset method to TGTest. I wouldn't make resetting config values automatic, since you might want the same config setting for several tests.

comment:2 Changed 11 years ago by Chris Arndt

  • Keywords testutil, needs feedback added
  • Description modified (diff)

comment:3 Changed 11 years ago by kvdb

If you'd want the same config settings for several tests, i'd include them in setUp(). Carrying any sort of state over different tests isn't helpful. The order in which the tests are run shouldn't matter in my opinion.

But at least having the possibility to call reset() is very welcome...

comment:4 Changed 11 years ago by Chris Arndt

Ken, I agree with your reasoning and think it would be a good thing to implement automatic config backup and restoring in testutil.TGTest. Do you have an implementation for this?

Changed 10 years ago by kskuhlman

Automatic config reset for testutil.TGTest

comment:5 Changed 10 years ago by kskuhlman

  • Status changed from new to assigned
  • Owner changed from anonymous to kskuhlman

I like Kees' idea, too. The implementation can be kept pretty simple. See the attachment that I just added for one solution.

comment:6 Changed 10 years ago by kskuhlman

  • Status changed from assigned to closed
  • Keywords testutil added; testutil, needs feedback removed
  • Resolution set to fixed

Applied to 1.1 in r6558. Change was applied earlier to 1.5 (inadvertently, in r6555).

Thanks for the idea!

Note: See TracTickets for help on using tickets.