Configuring TeamCity to run Python tests upon commit

TeamCity can be configured to invoke your test suite upon commit.

Getting ready

The following steps will help us prep are TeamCity to run our test suite when the code changes are committed:

  1. Set up TeamCity like the previous recipe, and have it started up. You also need to have git installed, as mentioned earlier in this chapter.
  2. Create an empty folder for this recipe.
    gturnquist$ mkdir /tmp/recipe49
    
  3. Initialize the folder for source code maintenance.
    gturnquist$ git init /tmp/recipe49
    Initialized empty Git repository in /private/tmp/recipe49/.git/
  4. Copy the shopping cart application into the folder, add it, and commit the changes.
    gturnquist$ cp cart.py /tmp/recipe49/
    gturnquist$ cd /tmp/recipe49/
    gturnquist$ git add cart.py
    gturnquist$ git commit -m "Added shopping cart application to setup this recipe."
    [master (root-commit) 057d936] Added shopping cart application to setup this recipe.
     1 files changed, 35 insertions(+), 0 deletions(-)
     create mode 100644 cart.py
    

How to do it...

These steps will show us how to create a TeamCity job that polls version control to detect a change and then run a test suite.

  1. Login to TeamCity console.
  2. Underneath Projects tab, click Create project.
  3. Type in recipe49, and then click Create.
  4. Click Add a build configuration for this project.
  5. Enter nose testing for the name and then click VCS settings.
  6. Click on Create and attach new VCS root.
  7. Enter recipe49 in VCS root name.
  8. Select Git as the Type of VCS.
  9. Enter /tmp/recipe49 as the Fetch URL.
  10. Click on Test Connection to confirm settings and then click Save.
  11. Click on Add Build Step.
  12. Select Command Line for Runner type.
  13. Select Custom script for Run type and enter the following script:
    . /Users/gturnquist/ptc/bin/activate
    nosetests tests.py

    You must replace this with the command to activate your own virtualenv and invoke nosetests.

  14. Click on Save.
  15. Click on Build Triggering.
  16. Click on Add New Trigger.
  17. Pick VCS Trigger from Trigger Type.
  18. At the top, it should display VCS Trigger will add build to the queue if VCS check-in is detected. Click Save.
  19. Navigate back to Projects. There should be no jobs scheduled or results displayed.
  20. Click on Run. It should fail, because we haven't added the tests to the repository.
    How to do it...
  21. From the command line, copy the test file into the repository. Then add it and commit it.
    gturnquist$ cp tests.py /tmp/recipe49/
    gturnquist$ cd /tmp/recipe49/
    gturnquist$ git add tests.py
    gturnquist$ git commit -m "Adding tests."
    [master 4c3c418] Adding tests.
     1 files changed, 20 insertions(+), 0 deletions(-)
     create mode 100644 tests.py
    
  22. Go back to the browser. It may take a minute for TeamCity to detect the change in the code and start another build job. It should automatically update the screen.
    How to do it...

How it works...

In this recipe, we configured TeamCity to do a job for us tied to a specific trigger. The trigger is: whenever a check in is done to the software baseline. We had to take several steps to configure this, but it demonstrates the flexible power TeamCity offers.

We also installed the teamcity-nose plugin, which gave us more details on the results.

There's more...

TeamCity calls our nose testing job a build job. That is because running tests isn't the only thing TeamCity is used for. Instead, it's geared to build packages, deploy to sites, and any other action we may want it to do anytime a commit happens. This is why CI servers are sometimes called build servers.

But if we start with simple jobs like testing the baseline, we are well on our way to discovering the other useful features TeamCity has to offer.

What did teamcity-nose give us?

This is a nose plugin that provided us with more detailed output. We didn't go into much detail in this recipe.

See also

  • Generating a CI report for TeamCity using teamcity-nose
  • Configuring Jenkins to run Python tests upon commit
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.47.208