Hi Carl,

On Monday 27 May 2013 19:37:55 Carl Meyer wrote:
> Hi Shai,
> 
> On 05/27/2013 09:26 AM, Shai Berger wrote:
> > I'm working on fixing some failing tests under Oracle, and I ran into
> > 
> >     commands_sql.tests.SQLCommandsTestCase.test_sql_all()
> > 
> > [...]
> > 
> > For now, I will only special-case Oracle -- that should solve a standing,
> > release-blocker bug, and not change the semantics of the test otherwise;
> > but I'd like to achieve something better, more general and
> > 3rd-party-backend- friendly, for the future.
> 
> It seems to me that ideally a test for backend-specific behavior should
> become a test for that backend (and thus skipped on other backends).
> This also solves the third-party-backend problem; said backend should
> have its own tests as needed, and Django's tests for backend-specific
> behavior should be skipped under any unrecognized backend.

I agree in general, but this can lead to DRY violations if we're not careful. 
A better example of the problem is a test next to the one I needed to fix:

    def test_sql_delete(self):
        app = models.get_app('commands_sql')
        output = sql_delete(app, no_style(), connections[DEFAULT_DB_ALIAS])
        # Oracle produces DROP SEQUENCE and DROP TABLE for this command.
        if connections[DEFAULT_DB_ALIAS].vendor == 'oracle':
            sql = output[1].lower()
        else:
            sql = output[0].lower()
        six.assertRegex(self, sql, r'^drop table .commands_sql_book.*')

Does any backend beside Oracle produce extra SQL for this command? Does the 
different command index for Oracle justify separating this test into two 
separate methods? And if you separate, would you mark the non-oracle case with 
skipIf(Oracle) or with skipUnless(sqlite or postgres or mysql) ?

I think a better solution for this is to keep the original method, and mark it 
with skipUnless(is_core_db) -- we'd need to define is_core_db for that, of 
course; this could also serve as an easy-to-grep marker for "general 
functionality test, with backend variations" -- which I think would be quite 
useful for 3rd-party backend writers.

Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to