Distutils
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 allows us to pass in a dict containing command names mapped to a command class. We configure the test command and map it to our TestCommand class.
The TestCommand...