Perfom python unit tests via a web interface

2024/10/10 20:19:38

Is it possible to perform unittest tests via a web interface...and if so how?

EDIT: For now I want the results...for the tests I want them to be automated...possibly every time I make a change to the code. Sorry I forgot to make this more clear

Answer

EDIT:

This answer is outdated at this point:

  • Use Jenkins instead of Hudson (same thing, new name).
  • Use django-jenkins instead of xmlrunner.py.

The link to django-jenkins goes to a nice tutorial on how to use Jenkins with Django. I'll leave the text below since it still has some nice information.


As Bryan said, I'd use Hudson to schedule, run, and collect the test results. You can modify your tests to use xmlrunner.py (written by Sebastian Rittau), which will output your test results into an JUnit compatible XML file for Hudson.

Here's an example of how the test code would use xmlrunner:

import unittest
import xmlrunnerclass TheTest(unittest.TestCase):def testOne(self):self.assertEquals(1, 1)def testTwo(self):self.assertEquals(2, 2)def testThree(self):self.assertEquals(3, 4)if __name__ == '__main__':suite = unittest.TestLoader().loadTestsFromTestCase(TheTest)xmlrunner.XMLTestRunner().run(suite)

Once you install Hudson, you'll create a new project for the source repository you're testing. You'll need to RTFM, but in a nutshell:

  1. Under Source Code Management, you'll enter your repositories information and make it poll the repo periodically (I usually just do * * * * * so it checks every minute)
  2. Add a command that actually runs the test script (like python test.py).
  3. Check the Publish JUnit test result report. If it has an error like 'TEST-*.xml' doesn't match anything you can safely ignore it. It'll look something like this: JUnit Settings
    (source: snowpeaksoftware.com)

Once that's all done you'll be able to see test results for every time Hudson runs after check-in. It'll look something like this:

Hudson Unit Test Results
(source: snowpeaksoftware.com)

You also get more detailed pages like this page:

Hudson Unit Test Detailed Results
(source: snowpeaksoftware.com)

and this page:

Hudson Unit Test Detailed Results
(source: snowpeaksoftware.com)

https://en.xdnf.cn/q/69859.html

Related Q&A

Limit on number of HDF5 Datasets

Using h5py to create a hdf5-file with many datasets, I encounter a massive Speed drop after ca. 2,88 mio datasets. What is the reason for this?I assume that the limit of the tree structure for the dat…

Object level cascading permission in Django

Projects such as Django-guardian and django-permissions enables you to have object level permissions. However, if two objects are related to each other by a parent-child relationship, is there any way …

How do I find out eigenvectors corresponding to a particular eigenvalue of a matrix?

How do I find out eigenvectors corresponding to a particular eigenvalue? I have a stochastic matrix(P), one of the eigenvalues of which is 1. I need to find the eigenvector corresponding to the eigen…

How to install my custom Python package with its custom dependencies?

I would like to find a way to install my own python package which depends on other custom python packages. I followed this guide to create my own python packages: https://python-packaging.readthedocs.i…

How to call a function only Once in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.The com…

Generating Compound Pie, or Pie of Pie Charts

Below is an example of a compound pie chart, also known as a pie of pie chart drawn using Excel. Is it possible to create a figure like this using python?

GitPython : git push - set upstream

Im using GitPython to clone a master branch and do a checkout of a feature branch, I do my local updates, commit and push back to git. The code snippet looks like below, Note : my branch name is featur…

How to access multi-level index in pandas data frame?

I would like to call those row with same index.so this is the example data frame, arrays = [np.array([bar, bar, baz, baz, foo, foo, qux, qux]), np.array([one, two, one, two, one, two, one, two])]df = p…

How to represent graphs with IPython

Recently I discovered IPython notebook which is a powerful tool. As an IT student, I was looking for a way to represent graphs in Python. For example, I would like to know if theres a library (like num…

How to check TypeVars Type at runtime

I have a generic class Graph[Generic[T], object]. My question, is there any function which returns type passed as generic to the class Graph>>> g = Graph[int]() >>> magic_func(g) <…