{"id":39,"date":"2011-01-24T19:13:14","date_gmt":"2011-01-24T18:13:14","guid":{"rendered":"http:\/\/blog.gocept.com\/?p=39"},"modified":"2012-12-03T15:11:44","modified_gmt":"2012-12-03T14:11:44","slug":"testing-pyramid-applications-with-zope-testbrowser","status":"publish","type":"post","link":"https:\/\/blog.gocept.com\/2011\/01\/24\/testing-pyramid-applications-with-zope-testbrowser\/","title":{"rendered":"Testing pyramid applications with zope.testbrowser"},"content":{"rendered":"

The Pyramid<\/a> documentation recommends<\/a> using WebTest<\/a> for functional tests, but coming from the Zope world, zope.testbrowser<\/a> is the more familiar tool for this job (and it seems a little more high-level than WebTest at first glance).<\/p>\n

With the 3.11 release,\u00a0 zope.testbrowser gained out-of-the-box support for talking to WSGI applications (courtesy of wsgi_intercept<\/a>), so herewith some corresponding example code to show the basic usage and setup. (This assumes you are using zope.testrunner or something else that supports its layers).<\/p>\n

\r\n
import unittest\r\nimport zope.testbrowser.wsgi\r\n\r\nclass MyAppLayer(zope.testbrowser.wsgi.Layer):\r\n\r\n    def make_wsgi_app(self):\r\n        from myapp import main\r\n        return main({})\r\n\r\nMY_APP_LAYER = MyAppLayer()\r\n\r\nclass FunctionalTests(unittest.TestCase):\r\n\r\n    layer = MY_APP_LAYER\r\n\r\n    def test_root(self):\r\n        browser = zope.testbrowser.wsgi.Browser()\r\n        browser.open('http:\/\/localhost\/')\r\n        self.failUnless('Pyramid' in browser.contents)<\/pre>\n","protected":false},"excerpt":{"rendered":"

The Pyramid documentation recommends using WebTest for functional tests, but coming from the Zope world, zope.testbrowser is the more familiar tool for this job (and it seems a little more high-level than WebTest at first glance). With the 3.11 release,\u00a0 zope.testbrowser gained out-of-the-box support for talking to WSGI applications (courtesy of wsgi_intercept), so herewith some … Continue reading “Testing pyramid applications with zope.testbrowser”<\/span><\/a><\/p>\n","protected":false},"author":10315341,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[10221],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pFP3y-D","jetpack-related-posts":[{"id":2351,"url":"https:\/\/blog.gocept.com\/2017\/05\/03\/zope-2-resurrection-sprint-day-1\/","url_meta":{"origin":39,"position":0},"title":"Zope 2 Resurrection Sprint \u2013 Day 1","author":"Michael Howitz","date":"May 3, 2017","format":false,"excerpt":"Welcome to the\u00a0Zope 2 Resurrection Sprint in Halle (Saale), Germany. We hope you enjoyed the time since the\u00a0Last call for take off to the Python 3 wonderland. We already achieved some things: Zope 4 no longer depends on\u00a0sourcecodegen\u00a0which was one of Zope's dependencies Earl Zope II\u00a0had to leave behind for\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":120,"url":"https:\/\/blog.gocept.com\/2011\/11\/03\/assertion-helper-for-zope-testbrowser-and-unittest\/","url_meta":{"origin":39,"position":1},"title":"Assertion helper for zope.testbrowser and unittest","author":"","date":"November 3, 2011","format":false,"excerpt":"zope.testbrowser is a valuable tool for integration tests. Historically,\u00a0 the Zope community used to write quite a lot of doctests, but we at gocept have found them to be rather clumsy and too often yielding neither good tests nor good documentation. That's why we don't use doctest much anymore, and\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1752,"url":"https:\/\/blog.gocept.com\/2016\/10\/04\/zope-resurrection-part-2-defibrillation\/","url_meta":{"origin":39,"position":2},"title":"Zope Resurrection Part 2 \u2013 Defibrillation","author":"Michael Howitz","date":"October 4, 2016","format":false,"excerpt":"After\u00a0reanimation\u00a0we started\u00a0defibrillation of Zope and \u2026 it kinda worked: On our\u00a0sprint we got\u00a0the following things done to help\u00a0Zope in the Python 3 wonderland: Release\u00a0zope.testbrowser 5.0\u00a0which is compatible with Python 3 and no longer uses\u00a0mechanize. PullRequest for\u00a0ExtensionClass\u00a0with the Python 3 port of the C extension. five.globalrequest\u00a0is now compatible with Python 3.\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2016\/10\/zopesprint.jpg?fit=1200%2C709&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2016\/10\/zopesprint.jpg?fit=1200%2C709&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2016\/10\/zopesprint.jpg?fit=1200%2C709&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2016\/10\/zopesprint.jpg?fit=1200%2C709&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2016\/10\/zopesprint.jpg?fit=1200%2C709&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1357,"url":"https:\/\/blog.gocept.com\/2013\/08\/20\/viewing-scales-metrics-from-pyramid\/","url_meta":{"origin":39,"position":3},"title":"Viewing scales metrics from Pyramid","author":"","date":"August 20, 2013","format":false,"excerpt":"We've recently started experimenting with the excellent scales library to collect in-process metrics (see Coda Hale's CodeConf talk \"Metrics everywhere\" among many others for reasons why one definitely wants to do that). Scales comes with a flask-based HTTP server that allows viewing the collected measurements and dumping them as JSON.\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":349,"url":"https:\/\/blog.gocept.com\/2012\/12\/17\/yafowil-in-a-pyramid-project\/","url_meta":{"origin":39,"position":4},"title":"yafowil in a Pyramid project","author":"Michael Howitz","date":"December 17, 2012","format":false,"excerpt":"In a new Pyramid\u00a0project we used deform\u00a0to render forms. We did not really like it. (The reasons might be detailed in another post.) To see if other form libraries do better I\u00a0gave yafowil\u00a0a try at our\u00a0gocept Developer Punsch\u00a03: yafowil comes with written documentation. To get a form in our Pyramid\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1293,"url":"https:\/\/blog.gocept.com\/2013\/05\/29\/august-15th-17th-sprinting-on-pyramid\/","url_meta":{"origin":39,"position":5},"title":"August, 15th\u201317th: Sprinting on Pyramid","author":"Daniel Havlik","date":"May 29, 2013","format":false,"excerpt":"After Zope \"-the-Framework\" reaching the end of its lifecycle during the last few years, we did a bunch of new projects with Pyramid, a nice web framework primarily authored by long-term Zope developer Chris McDonough. We think it's about time to give something back to the community, and become more\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/39"}],"collection":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/users\/10315341"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":5,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":97,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/39\/revisions\/97"}],"wp:attachment":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}