#!/usr/bin/env python
"""Script to collect coverage information on ofStateManager"""

import os
import sys
import inspect
import coverage
import subprocess


def main():
	"""Main function"""
	arguments = ''
	if len(sys.argv) > 1:
		arguments = ' '.join(sys.argv[1:])
	testdir = os.path.abspath(os.path.dirname(
			inspect.getfile(inspect.currentframe())))
	os.environ['COVERAGE_PROCESS_START'] = os.path.join(testdir, '.coveragerc')
	os.environ['COVERAGE_FILE'] = os.path.join(testdir, '.coverage')
	cov = coverage.coverage(source=os.path.join(testdir, '..'),
		include=os.path.join(testdir, '..', 'ofStateManager.py'))
	cov.erase()
	subprocess.call('coverage run -m py.test ' + arguments, shell=True,
					cwd=testdir)
	cov.combine()
	cov.html_report(directory=os.path.join(testdir, 'htmlcov'))
	cov.report(show_missing=False)

if __name__ == '__main__':
	main()

#!/usr/bin/env python
"""Script to collect coverage information on ofStateManager"""

import os
import sys
import inspect
import coverage
import subprocess


def main():
	"""Main function"""
	arguments = ''
	if len(sys.argv) > 1:
		arguments = ' '.join(sys.argv[1:])
	testdir = os.path.abspath(os.path.dirname(
			inspect.getfile(inspect.currentframe())))
	script_path = os.path.join(testdir, '..', 'ofStateManager.py')

	os.environ['COVERAGE_PROCESS_START'] = os.path.join(testdir, '.coveragerc')
	os.environ['COVERAGE_FILE'] = os.path.join(testdir, '.coverage')

	subprocess.call('coverage erase', shell=True, cwd=testdir)
	subprocess.call('coverage run -m py.test ' + arguments, shell=True, cwd=testdir)
	subprocess.call('coverage combine', shell=True, cwd=testdir)
	subprocess.call('coverage html -d ' + os.path.join(testdir, 'htmlcov') +
					' --include=' + script_path, shell=True, cwd=testdir)
	subprocess.call('coverage report --include=' + script_path,
					shell=True, cwd=testdir)


if __name__ == '__main__':
	main()

Replace coverage API calls by subprocess calls.
Replace coverage API calls by subprocess calls.