简体   繁体   中英

Integrating setup.py with Makefile to run tests

I used to run the tests for my packages from the Makefile as a way to perform three tasks in one: setup a virtual environment, install requirements and call the testing suite with the corresponding arguments:

test: venv
  env/bin/pip install -r test_requirements.txt
  env/bin/nosetests --rednose --with-coverage --cover-pagacke my_module

Then I read that requirements.txt files are discouraged in favor of setup.py, so I modified the setup.py file aiming to get the same result:

setup(
    ...
    tests_require=['nose', 'rednose', 'coverage'],
    test_suite=['nose.collector'])

Now I could change the Makefile with

test: venv
    coverage run --source=my_module/ setup.py test

But that requires installing the testing dependencies before running the setup.py file. I'm also not sure how to include other arguments such as rednose. What is the best way to do this?

Tox is good and all, but here's how to do it without having to install any other package beforehand.

List the testing dependencies as setup_requires instead of tests_require in the setup.py file

setup(
    setup_requires=['nose', 'rednose', 'coverage'],
    install_requires=[]  # fill in other arguments as usual
)

Optionally add test parameters to the setup.cfg file.

[nosetests]
rednose=1
detailed-errors=1
with-coverage=1
cover-package=server
cover-xml=1
verbosity=2

Run the tests with the following command

python setup.py nosetests

Source: http://nose.readthedocs.io/en/latest/api/commands.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM