April 2015
Intermediate to advanced
264 pages
5h 31m
English
Python comes bundled with its own packaging system called distutils. Although setuptools is the preferred way, we might sometimes want to stick with distutils because it is bundled in the standard library.
Distutils supports adding custom commands to setup.py. We're going to use that feature to add a command that will run our tests. The following is what it looks like:
import subprocess
from distutils.core import setup, Command
class TestCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
p = subprocess.Popen(["python", "-m", "unittest"])
p.wait()
raise SystemExit(p.returncode)
setup(
name="StockAlerter",
version="0.1",
cmdclass={
"test": TestCommand
}
)The cmdclass option ...
Read now
Unlock full access