Ability to execute code at regular intervals in between unit tests?

17 views
Skip to first unread message

Ignacio Tripodi

unread,
Oct 20, 2015, 5:55:51 PM10/20/15
to nose-users
Hi,

I was wondering if there would be a way to tell nose to execute something (a single line of Python would do) at regular intervals (say, once an hour) in between running unit tests. We have an extensive regression tests suite that runs for 12 hours or more with "--randomize", and a few unit tests that fail intermittently due to platform constraints that could be resolved by executing this action at regular intervals. I could hack this into one of our core libraries but I'd rather use a built-in feature, if already present.
Thanks for any feedback you could provide!

-i

Dan Stromberg

unread,
Feb 25, 2016, 8:04:19 PM2/25/16
to nose-users

Corentin Henry

unread,
Mar 1, 2016, 5:11:32 PM3/1/16
to nose-users
Hi,


I know, you use nose. But if using nose2 is an alternative, you could do this via a pretty simple plugin.

For example the `startTest` hooks (http://nose2.readthedocs.org/en/latest/dev/hook_reference.html#startTest) does exactly what you're asking for: executing arbitrary code before each test.

Example:


class MyPlugin(nose2.events.Plugin):

    def startTestRun(self, event):
        # this hook is called when the run starts
        # we use it to keep track of the start time
        self.start_time = time.time()
       
    def startTestRun(self, event):
        if time.time() - self.start_time > 3600:
            do_some_stuff()


It has probably been said on the ML before but nose is not actively maintained anymore, so you might want to consider using nose2, which I'm currently maintaining.


Cheers,
Corentin

Ignacio Tripodi

unread,
Mar 1, 2016, 5:17:17 PM3/1/16
to nose-...@googlegroups.com

Thanks! I'll certainly explore this, as I'm not currently married to nose. Just would need to look at what effort is required to port the current scripts to nose2.

--
You received this message because you are subscribed to a topic in the Google Groups "nose-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nose-users/sovyuByom8s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nose-users+...@googlegroups.com.
To post to this group, send email to nose-...@googlegroups.com.
Visit this group at https://groups.google.com/group/nose-users.
For more options, visit https://groups.google.com/d/optout.

Corentin Henry

unread,
Mar 1, 2016, 5:43:15 PM3/1/16
to nose-users
For most cases it should work out of the box :)
You can try actually: install nose2, and see if it discovers and run your tests running `nose2`.

See also: https://nose2.readthedocs.org/en/latest/usage.html
For the differences with nose: https://nose2.readthedocs.org/en/latest/differences.html

If you have any problem, don't hesitate to file an issue on github, this is where I'm the most active: https://github.com/nose-devs/nose2/issues
Reply all
Reply to author
Forward
0 new messages