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.