Skip to content

Instantly share code, notes, and snippets.

@manuphatak
Created December 8, 2015 05:47
Show Gist options
  • Save manuphatak/d3e36133aeba95e46390 to your computer and use it in GitHub Desktop.
Save manuphatak/d3e36133aeba95e46390 to your computer and use it in GitHub Desktop.
Dealing with `atexit` and setup.py test command deleting modules.
from setuptools import setup
from setuptools.command.test import test as TestCommand
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import pytest
import sys
errno = pytest.main(self.test_args)
self.handle_exit()
sys.exit(errno)
@staticmethod
def handle_exit():
import atexit
atexit._run_exitfuncs()
setup(cmdclass={'test': PyTest})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment