lundi 7 septembre 2015

nosetests gives different results in different directories

I have a project where I am wanting to run my code in the context of a daemon. I am using a daemon class from here :

http://ift.tt/1fwEF7g

I wanted to run a simple test to confirm that my daemon is starting and stopping properly and a few other things. I have that test in my test directory and my directory layout is like so:

mydaemon
    mydaemon
        /__init__.py
        /daemon.py
        /mydaemonrunner.py
    tests
        /test_mydaemonrunner.py          

When I run nosetests from inside the test directory, my test passes without an issue. However, when I run nosetests from the root mydaemon directory I get a called process error. Here is the test that I'm passing in...

class test_mydaemonrunner(unittest.TestCase):
    def setUp(self):
        output = subprocess.check_output(["sudo","python","../mydaemon/mydaemonrunner.py","start",stderr=subprocess.STDOUT)
        m = re.match("started with pid (\d+)", output)
        if m:
            self.process_pid = m(1)
        else:
            print "Test Setup was not successful"

For the record, the error that is being raised is a CalledProcessError.

So, my question is:

What could cause nosetests to fail when running in the root directory of my project but to pass when run in the tests directory? And is there a preferred directory structure that will minimize these sorts of issues?

Aucun commentaire:

Enregistrer un commentaire