testtools


Nametesttools JSON
Version 2.7.1 PyPI version JSON
download
home_page
SummaryExtensions to the Python standard library unit testing framework
upload_time2023-11-02 10:49:40
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements fixtures
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ======================================
testtools: tasteful testing for Python
======================================

testtools is a set of extensions to the Python standard library's unit testing
framework. These extensions have been derived from many years of experience
with unit testing in Python and come from many different sources.

What better way to start than with a contrived code snippet?::

  from testtools import TestCase
  from testtools.content import Content
  from testtools.content_type import UTF8_TEXT
  from testtools.matchers import Equals

  from myproject import SillySquareServer

  class TestSillySquareServer(TestCase):

      def setUp(self):
          super(TestSillySquareServer, self).setUp()
          self.server = self.useFixture(SillySquareServer())
          self.addCleanup(self.attach_log_file)

      def attach_log_file(self):
          self.addDetail(
              'log-file',
              Content(UTF8_TEXT,
                      lambda: open(self.server.logfile, 'r').readlines()))

      def test_server_is_cool(self):
          self.assertThat(self.server.temperature, Equals("cool"))

      def test_square(self):
          self.assertThat(self.server.silly_square_of(7), Equals(49))


Why use testtools?
==================

Matchers: better than assertion methods
---------------------------------------

Of course, in any serious project you want to be able to have assertions that
are specific to that project and the particular problem that it is addressing.
Rather than forcing you to define your own assertion methods and maintain your
own inheritance hierarchy of ``TestCase`` classes, testtools lets you write
your own "matchers", custom predicates that can be plugged into a unit test::

  def test_response_has_bold(self):
     # The response has bold text.
     response = self.server.getResponse()
     self.assertThat(response, HTMLContains(Tag('bold', 'b')))


More debugging info, when you need it
--------------------------------------

testtools makes it easy to add arbitrary data to your test result.  If you
want to know what's in a log file when a test fails, or what the load was on
the computer when a test started, or what files were open, you can add that
information with ``TestCase.addDetail``, and it will appear in the test
results if that test fails.


Extend unittest, but stay compatible and re-usable
--------------------------------------------------

testtools goes to great lengths to allow serious test authors and test
*framework* authors to do whatever they like with their tests and their
extensions while staying compatible with the standard library's unittest.

testtools has completely parametrized how exceptions raised in tests are
mapped to ``TestResult`` methods and how tests are actually executed (ever
wanted ``tearDown`` to be called regardless of whether ``setUp`` succeeds?)

It also provides many simple but handy utilities, like the ability to clone a
test, a ``MultiTestResult`` object that lets many result objects get the
results from one test suite, adapters to bring legacy ``TestResult`` objects
into our new golden age.


Cross-Python compatibility
--------------------------

testtools gives you the very latest in unit testing technology in a way that
will work with Python 3.7+ and PyPy3.

If you wish to use testtools with Python 2.4 or 2.5, then please use testtools
0.9.15.

If you wish to use testtools with Python 2.6 or 3.2, then please use testtools
1.9.0.

If you wish to use testtools with Python 3.3 or 3.4, then please use testtools 2.3.0.

If you wish to use testtools with Python 2.7 or 3.5, then please use testtools 2.4.0.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "testtools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "\"Jonathan M. Lange\" <jml+testtools@mumak.net>",
    "download_url": "https://files.pythonhosted.org/packages/07/a7/3f3daee7a525d5288b84581448d21a39d0b9ae9f4a235d99850682944857/testtools-2.7.1.tar.gz",
    "platform": null,
    "description": "======================================\ntesttools: tasteful testing for Python\n======================================\n\ntesttools is a set of extensions to the Python standard library's unit testing\nframework. These extensions have been derived from many years of experience\nwith unit testing in Python and come from many different sources.\n\nWhat better way to start than with a contrived code snippet?::\n\n  from testtools import TestCase\n  from testtools.content import Content\n  from testtools.content_type import UTF8_TEXT\n  from testtools.matchers import Equals\n\n  from myproject import SillySquareServer\n\n  class TestSillySquareServer(TestCase):\n\n      def setUp(self):\n          super(TestSillySquareServer, self).setUp()\n          self.server = self.useFixture(SillySquareServer())\n          self.addCleanup(self.attach_log_file)\n\n      def attach_log_file(self):\n          self.addDetail(\n              'log-file',\n              Content(UTF8_TEXT,\n                      lambda: open(self.server.logfile, 'r').readlines()))\n\n      def test_server_is_cool(self):\n          self.assertThat(self.server.temperature, Equals(\"cool\"))\n\n      def test_square(self):\n          self.assertThat(self.server.silly_square_of(7), Equals(49))\n\n\nWhy use testtools?\n==================\n\nMatchers: better than assertion methods\n---------------------------------------\n\nOf course, in any serious project you want to be able to have assertions that\nare specific to that project and the particular problem that it is addressing.\nRather than forcing you to define your own assertion methods and maintain your\nown inheritance hierarchy of ``TestCase`` classes, testtools lets you write\nyour own \"matchers\", custom predicates that can be plugged into a unit test::\n\n  def test_response_has_bold(self):\n     # The response has bold text.\n     response = self.server.getResponse()\n     self.assertThat(response, HTMLContains(Tag('bold', 'b')))\n\n\nMore debugging info, when you need it\n--------------------------------------\n\ntesttools makes it easy to add arbitrary data to your test result.  If you\nwant to know what's in a log file when a test fails, or what the load was on\nthe computer when a test started, or what files were open, you can add that\ninformation with ``TestCase.addDetail``, and it will appear in the test\nresults if that test fails.\n\n\nExtend unittest, but stay compatible and re-usable\n--------------------------------------------------\n\ntesttools goes to great lengths to allow serious test authors and test\n*framework* authors to do whatever they like with their tests and their\nextensions while staying compatible with the standard library's unittest.\n\ntesttools has completely parametrized how exceptions raised in tests are\nmapped to ``TestResult`` methods and how tests are actually executed (ever\nwanted ``tearDown`` to be called regardless of whether ``setUp`` succeeds?)\n\nIt also provides many simple but handy utilities, like the ability to clone a\ntest, a ``MultiTestResult`` object that lets many result objects get the\nresults from one test suite, adapters to bring legacy ``TestResult`` objects\ninto our new golden age.\n\n\nCross-Python compatibility\n--------------------------\n\ntesttools gives you the very latest in unit testing technology in a way that\nwill work with Python 3.7+ and PyPy3.\n\nIf you wish to use testtools with Python 2.4 or 2.5, then please use testtools\n0.9.15.\n\nIf you wish to use testtools with Python 2.6 or 3.2, then please use testtools\n1.9.0.\n\nIf you wish to use testtools with Python 3.3 or 3.4, then please use testtools 2.3.0.\n\nIf you wish to use testtools with Python 2.7 or 3.5, then please use testtools 2.4.0.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Extensions to the Python standard library unit testing framework",
    "version": "2.7.1",
    "project_urls": {
        "Homepage": "https://github.com/testing-cabal/testtools"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a8aac002f3794e92a2820717b246719598a722e33970c7cc17413094a6bbdd7",
                "md5": "91dc3067fdc3c313100ddbd57c7904a0",
                "sha256": "56e118ce251544d436d9fbb5ba62f44aeb237aa8fcc3147372b484bbe5f48ef7"
            },
            "downloads": -1,
            "filename": "testtools-2.7.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "91dc3067fdc3c313100ddbd57c7904a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 179839,
            "upload_time": "2023-11-02T10:49:38",
            "upload_time_iso_8601": "2023-11-02T10:49:38.033659Z",
            "url": "https://files.pythonhosted.org/packages/5a/8a/ac002f3794e92a2820717b246719598a722e33970c7cc17413094a6bbdd7/testtools-2.7.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "07a73f3daee7a525d5288b84581448d21a39d0b9ae9f4a235d99850682944857",
                "md5": "a5fe6dfb29476879ce4dd0148e470e6c",
                "sha256": "df6de96010e29ee21f637a147eabf30d50b25e3841dd1d68f93ee89ce77e366c"
            },
            "downloads": -1,
            "filename": "testtools-2.7.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a5fe6dfb29476879ce4dd0148e470e6c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 200953,
            "upload_time": "2023-11-02T10:49:40",
            "upload_time_iso_8601": "2023-11-02T10:49:40.797730Z",
            "url": "https://files.pythonhosted.org/packages/07/a7/3f3daee7a525d5288b84581448d21a39d0b9ae9f4a235d99850682944857/testtools-2.7.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-02 10:49:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "testing-cabal",
    "github_project": "testtools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "fixtures",
            "specs": [
                [
                    ">=",
                    "2.0"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "testtools"
}
        
Elapsed time: 0.23339s