CleanCut / green

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

Is it possible to run tests using green programmatically? #50

Closed laike9m closed 9 years ago

CleanCut commented 9 years ago

Yes!

If you will tell me where in your process you want to launch them from, I can point you in the right direction. For example, is it from a Makefile? From bash? From another python script? From the test file itself?

CleanCut commented 9 years ago

I'm going to go ahead and close this issue, but feel free to reply if you would like help from me. I'll still get notified even though it's closed.

laike9m commented 9 years ago
tests = unittest.TestLoader().discover(
            os.path.join(setup_dir, 'tests'), pattern='*.py')
unittest.TextTestRunner().run(tests)

How to run this code using green?

kxepal commented 9 years ago

What's the point of using green in this place? unittest does discovery and testing well.

laike9m commented 9 years ago

@kxepal Quote from green's readme:

Green grew out of a desire to see pretty colors.

People use green for better discovering or testing? Of course not. If what I need is not prettier output, why do I use green?

CleanCut commented 9 years ago

@laike9m I believe something like this should work:

from green.suite import GreenTestSuite
from green.runner import run
from green.config import default_args
# If you want to change options, modify default_args here
# default_args.verbose = 3   # etc.
tests = unittest.TestLoader().discover(
            os.path.join(setup_dir, 'tests'), pattern='*.py')
run(GreenTestSuite(tests), sys.stdout, default_args)
laike9m commented 9 years ago

Thx CleanCut, I'll try.

laike9m commented 9 years ago

@CleanCut Works as expected. Thx again! Why don't you put it into documentation?

CleanCut commented 9 years ago

Well, if I'm going to officially support it, I'd rather add a new feature so it goes something more like:

from green import runTestSuite
tests = (however you want to manually load tests)
runTestSuite(tests)