Re: Pre-empting Fixture execution in Django with nosetests.

2008-10-01 Thread Kumar McMillan

On Tue, Sep 23, 2008 at 3:07 AM, proteus guy <[EMAIL PROTECTED]> wrote:
> Here's a fun one for you testing gurus! I have a Django app that uses an
> irc server to communicate events to a system. My models utilize the django
> model save signal to post an irc message when something is updated. For unit
> testing I've been able to monkey-patch the IRC connection object no problem
> and everything's dandy. However, most of the tests require fixture objects
> so a certain state is established prior to each test. Since fixtures get
> loaded prior to my unit test code getting loaded the monkey-patching hasn't
> occurred yet and the save signal for the fixture model objects is causing
> the system to attempt to talk to a real irc server. According to the Django
> documentation I can use settings.TEST_RUNNER to get control of the
> fixture/test discovery/execution but this only works for manage.py and is
> ignored by nosetests (and its Django plugin).
>
> Appreciate any ideas...

As Russ said, you can try to wrap up nosetests into your own
run_tests() method but IIRC the Django plugin for nose is already
hooking into setup_test_environment() which is what is loading your
fixture data (I think).  To do some monkey patching before fixtures
are loaded then you can create a custom nose plugin and give it a
score attribute of 1 so that it gets executed before nose's Django
plugin.

Docs and recipes for writing plugins are here:
http://somethingaboutorange.com/mrl/projects/nose/doc/writing_plugins.html

You probably want something simple like this:

import os
from nose.plugins.base import Plugin

class MonkeyPatch(Plugin):
enabled = True
name = 'mokeypatch'
score = 1

def options(self, parser, env=os.environ):
pass

def configure(self, options, conf):
pass

def begin(self):
monkey_patch_whatever()

>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Pre-empting Fixture execution in Django with nosetests.

2008-09-24 Thread Russell Keith-Magee

On Wed, Sep 24, 2008 at 4:39 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> Russ,
>
> Well, as you can tell from my initial post, this was my initial
> concept. However, you seem to be proposing to launch nosetests from
> the 'manage.py test' execution rather than directly from the command
> line. Am I reading you right? Hadn't considered that option. Not sure
> how much effort it would be so will have to dig into nosetests source
> to determine. Seems a bit complex at first glance, however.

Caveat: I am in no way an expert on nosetests, so I can't say for sure
that this is possible.

However, at the base level, the Django test runner (./manage.py test)
is just a way of calling a generic python function with an argument
specifying the test conditions (test names, verbosity etc). By
default, the test runner executes the default Python test framework,
but it should be possible to integrate any other test runner or
framework - as long as they expose some sort of 'run these tests'
function. It's just a matter of writing a test runner that can invoke
that function.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Pre-empting Fixture execution in Django with nosetests.

2008-09-24 Thread [EMAIL PROTECTED]

Russ,

Well, as you can tell from my initial post, this was my initial
concept. However, you seem to be proposing to launch nosetests from
the 'manage.py test' execution rather than directly from the command
line. Am I reading you right? Hadn't considered that option. Not sure
how much effort it would be so will have to dig into nosetests source
to determine. Seems a bit complex at first glance, however.

thanx,

  -- Ben

PS: Meanwhile for the specific model in question, I have moved the
fixtures under the test directory itself and have the unit test class
explicitly load those fixtures so my monkey-patch can happen prior to
the fixture load. Not a general solution but works for now.

On Sep 23, 7:55 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> The solution here is easy - write your own custom test runner. The
> default Django test runner monkeypatches the mail sending libraries
> and the template generation. You need to monkeypatch one of your
> internal capabilites, so you will need to write a custom test runner
> that does so. I haven't looked at the nosetests test runner, but I'd
> be surprised if it can't be substantially reused (or at the very
> least, copied) for your own custom test runner.
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Pre-empting Fixture execution in Django with nosetests.

2008-09-23 Thread Russell Keith-Magee

On Tue, Sep 23, 2008 at 4:07 PM, proteus guy <[EMAIL PROTECTED]> wrote:
> Here's a fun one for you testing gurus! I have a Django app that uses an
> irc server to communicate events to a system. My models utilize the django
> model save signal to post an irc message when something is updated. For unit
> testing I've been able to monkey-patch the IRC connection object no problem
> and everything's dandy. However, most of the tests require fixture objects
> so a certain state is established prior to each test. Since fixtures get
> loaded prior to my unit test code getting loaded the monkey-patching hasn't
> occurred yet and the save signal for the fixture model objects is causing
> the system to attempt to talk to a real irc server. According to the Django
> documentation I can use settings.TEST_RUNNER to get control of the
> fixture/test discovery/execution but this only works for manage.py and is
> ignored by nosetests (and its Django plugin).
>
> Appreciate any ideas...

The solution here is easy - write your own custom test runner. The
default Django test runner monkeypatches the mail sending libraries
and the template generation. You need to monkeypatch one of your
internal capabilites, so you will need to write a custom test runner
that does so. I haven't looked at the nosetests test runner, but I'd
be surprised if it can't be substantially reused (or at the very
least, copied) for your own custom test runner.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---