문제

I'm using Tox to check that the system I'm developing is behaving well when installed in a fresh environment (+ sanity checking the setup.py file). However, the system uses a memcached server, and ideally I'd like to spawn a new one for every Tox run.

Is there a preferred way to start programs before tests are run (and shut them down afterwards) or will I need to write a custom runner?

Edit: The test runner is py.test

도움이 되었습니까?

해결책 2

This isn't really a task for tox. My recommendation is that you do this in the setup functions/methods of the actual unit testing framework (py.test, nose, unittests, ...) you are using with tox.

Original poster's comment:

pytest_configure and pytest_unconfigure in conftest.py was a good place to spawn/terminate.

다른 팁

To elaborate on flub's comment on the best way to do it with py.test, using its fixture mechanism. Create a conftest.py file with this content:

# content of conftest.py

import pytest, subprocess

@pytest.fixture(scope="session", autouse=True)
def startmemcache(request):
    proc = subprocess.Popen(...)
    request.addfinalizer(proc.kill)

The "autouse" flag means that this fixture will be activated for each test run without requiring any references from tests. In practise, however, you might want to make the connection details to the subprocess available to your tests so that you don't have to work with magic port numbers. You wouldn't use "autouse" then but rather return a fixture object for connecting to memcache, nicely encapsulating test configuration in one place (the fixture function). See the docs for many more examples.

I recommend that you use paver - http://paver.github.com/paver/ - for the spawning up and shutting down of your memcached server or any additional "miscellaneous system admin tasks" that you need to do during the execution of setup.py by tox.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top