Search code examples
pythonunit-testingbuildout

How do I run unit tests on my Python code in Buildout?


I have a Python project which is managed by zc.buildout.

My buildout.cfg file looks like this:

[buildout]
parts = python ipython
develop = .
eggs = redditsubscraper
versions = versions

[versions]

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

[ipython]
recipe = zc.recipe.egg:scripts
eggs = ${buildout:eggs}
    ipython
scripts = ipython

I'd like to add a bin/test script for running unit tests on my library.

How can I add this script? Is there a recipe that I need which will enable me to run bin/test and have my unit tests run?


Solution

  • I found a way to do it.

    Add a new section to buildout.cfg:

    [test]
    recipe = pbp.recipe.noserunner
    eggs = ${buildout:eggs}
        pbp.recipe.noserunner
    script = test
    

    Add that section to your buildout:parts:

    [buildout]
    parts = python ipython test
    # ...
    

    Run bin/buildout and you'll get a script called test in the bin/ folder. Run that script to run all tests in your project.