CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
795 stars 76 forks source link

[question] setup.py integration #17

Closed faide closed 10 years ago

faide commented 10 years ago

I'd like a way to integrate with setup.py more finely than what is currently possible (to my understanding at least).

Here is the long story

I found the way to integrate with setup.py using this code:

test_suite='green.test',
tests_require=['coverage', 'green'],

but has you can see in my example I want to use coverage to produce reports.

What I did when using nose

in setup.py

test_suite='nose.collector',
tests_require=['nose', 'nosexcover'],

and in setup.cfg

[nosetests]
detailed-errors=1
with-doctest=1
verbose=True
with-xunit=True
with-xcoverage=True

[aliases]
test = nosetests --detailed-errors --with-doctest --cover-package=mypackage

but using green I cannot (did not find the way to) provide an alias and thus cannot force the production of a correct .coverage directory

Current situation & usage

At the same time running python setup.py test with test_suite='nose.collector' will generate a directory named like this: .coverage.1_7173 but the appended number will change at every run and the generated files will reference temporary files that are long gone before you can run coverage html

My solution for the moment is to no use test_suite='nose.collector' and provide a simple shell script like this:

runtests.sh

#!/bin/bash

# run the green test runner (pip install --upgrade green)
green -r <mypackagenamehere>

# then generate the coverage report (pip install --upgrade coverage)
coverage html

# then open coverage_html_report/index.html to review the results
CleanCut commented 10 years ago

Interesting to consider! I have a couple observations/questions:

1) When you say setup.py, I assume you are using setuptools inside of it. If that is not correct, please let me know.

2) According to the setuptools documentation, there are only options to help get the unit tests (test_suite and test_loader) and an option to specify what must be installed to run the tests (test_requires). I don't see anything about what runs the test. How did you get nose to run your tests through setup.py? According to this documentation the tests are always run using the built-in unittest module's runner. Maybe I'm missing something.

faide commented 10 years ago

1) is correct I use setuptools with from setuptools import setup

2) the important part here is the alias definition in setup.cfg and the fact that the nose.collector plugin will be able to interpret the [nosetests] section of setup.cfg to feed its config before running.

To be honest I did not reflect much on how it worked (since it worked pretty straight forward after a few tries). But I assume that nosetests is a setup.py "command" defined by the nose.collector plugin of nose and it accepts command lines and configuration setting from setup.cfg.

To be honest once more I hoped that you would fiddle in nose internals for me and I would just reap the benefits :-) But if you don't have an idea where it might be I may be lured into looking by myself and proposing a pull request

CleanCut commented 10 years ago

I have no idea where to start with this one. I took a look at nose internals for nose.collector and it didn't really shed any light on the subject. I welcome pull requests!

CleanCut commented 10 years ago

I'm going to close this one for now, since I have no idea where to start and I don't find it a very interesting feature. If anyone would like to at least figure out the roadmap of how to implement this, feel free to add that here and reopen the issue. (Or just implement it and submit a pull request!)

The current workaround would be instead of running

python setup.py test

run...

green subdirectory_code_is_in