Generating a CI report for TeamCity using teamcity-nose

There is a Nose plugin that automatically detects when tests are being run from inside the TeamCity. This conveniently captures test results and communicates them with TeamCity. With this recipe, we will explore how to setup a CI job inside TeamCity that runs our tests and then manually invokes that job.

Getting ready

The following steps are needed to get us prepared to run a TeamCity CI job:

  1. Install nosetests as shown in Chapter 2.
  2. Install teamcity-nose by typing pip install teamcity-nose.
  3. Download TeamCity using wget http://download.jetbrains.com/teamcity/TeamCity-6.0.tar.gz.
  4. Unpack the download.
  5. Switch to TeamCity/bin directory.
  6. Start it up: ./runAll.sh start.
  7. Open a browser to http://localhost:8111.
  8. If this is the first time you are starting TeamCity, accept the license agreement.
  9. Create an administrator account by picking a username and password.
  10. Install git source code control on your machine.
  11. Create an empty folder for this recipe.
    gturnquist$ mkdir /tmp/recipe48
    
  12. Initialize the folder for source code maintenance.
    gturnquist$ git init /tmp/recipe48
    Initialized empty Git repository in /private/tmp/recipe48/.git/
    
  13. Copy the shopping cart application and tests into the folder, add it, and commit the changes.
    gturnquist$ cp cart.py /tmp/recipe48/
    gturnquist$ cp tests.py /tmp/recipe48/
    gturnquist$ cd /tmp/recipe48/
    gturnquist$ git add cart.py tests.py
    gturnquist$ git commit -m "Added shopping cart and tests to setup this recipe."
    [master (root-commit) ccc7155] Added shopping cart and tests to setup this recipe.
     2 files changed, 55 insertions(+), 0 deletions(-)
     create mode 100644 cart.py
     create mode 100644 tests.py
    

How to do it...

The following steps will show us how to configure a CI job in TeamCity:

  1. Login to TeamCity console.
  2. Underneath Projects tab, click Create project.
  3. Type in recipe48, 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 recipe48 in VCS root name.
  8. Select Git as the Type of VCS.
  9. Enter /tmp/recipe48 as the Fetch URL.
  10. Click on Test Connection to confirm the 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 need to customize this with the command needed to activate your virtualenv.

  14. Click on Save.
  15. Go back to the project, and manually run it.
    How to do it...

How it works...

This plugin is designed not to be used in the classic style of being invoked by a command-line argument. Instead, it is automatically run whenever nosetests is executed, and it checks if there is a TeamCity-specific environment variable set. If so, it kicks in by printing out viewable results as well as sending back useful information to TeamCity.

How it works...

Otherwise, the plugin lets itself be bypassed and does nothing. If the plugin was NOT installed, the following screenshot would be the output:

How it works...

In turn, drilling into the details shows the following output with little detail. There are four periods, one for each test method, but we don't know much more than that.

How it works...

This means no extra arguments are needed to use the TeamCity plugin, but running it from the command line, outside of TeamCity, causes no changes.

..................Content has been hidden....................

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