From ffffac27f9a1f493df94b9b8d4fb3d77cd047664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Thu, 23 Jan 2014 09:46:36 +0100 Subject: [PATCH 1/6] document explicitly clearing local references to pytest.raises() results pytest.raises() returns an ExceptionInfo object which, if a local reference is made to it, forms a reference cycle: ExceptionInfo --> exception --> stack frame raising the exception --> current stack frame --> current local variables --> Exception Info Such a reference cycle would then prevent any local variables in the current stack frame, or any of its child stack frames involved in the same reference cycle, from being garbage collected until the next reference cycle garbage collection phase. This unnecessarily increases the program's memory footprint and potentially slows it down. This situation is based on a similar one described in the official 'try' statement Python documentation for locally stored exception references. --HG-- branch : document_ExceptionInfo_ref_cycle --- _pytest/python.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_pytest/python.py b/_pytest/python.py index 4ef5e9849..5c063b041 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -938,6 +938,12 @@ def raises(ExpectedException, *args, **kwargs): This helper produces a ``py.code.ExceptionInfo()`` object. + Note that any local references made to such returned + ``py.code.ExceptionInfo()`` objects should be explicitly cleared, as they + are part of a reference cycle similar to local references to caught Python + exception objects. See the official Python ``try`` statement documentation + for more detailed information. + If using Python 2.5 or above, you may use this function as a context manager:: From 75c124ea170d21160714f5c0264d8b4d1b594e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Thu, 23 Jan 2014 11:36:04 +0100 Subject: [PATCH 2/6] reword note on explicitly clearing local references to pytest.raises() results Made it clearer that clearing such references is not mandatory and is only an optional step which may help the Python interpreter speed up its garbage collection. --HG-- branch : document_ExceptionInfo_ref_cycle --- _pytest/python.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 5c063b041..91369fedb 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -938,12 +938,6 @@ def raises(ExpectedException, *args, **kwargs): This helper produces a ``py.code.ExceptionInfo()`` object. - Note that any local references made to such returned - ``py.code.ExceptionInfo()`` objects should be explicitly cleared, as they - are part of a reference cycle similar to local references to caught Python - exception objects. See the official Python ``try`` statement documentation - for more detailed information. - If using Python 2.5 or above, you may use this function as a context manager:: @@ -968,6 +962,22 @@ def raises(ExpectedException, *args, **kwargs): >>> raises(ZeroDivisionError, "f(0)") + + Performance note: + ----------------- + + Similar to caught exception objects in Python, explicitly clearing local + references to returned ``py.code.ExceptionInfo`` objects can help the Python + interpreter speed up its garbage collection. + + Clearing those references breaks a reference cycle (``ExceptionInfo`` --> + caught exception --> frame stack raising the exception --> current frame + stack --> local variables --> ``ExceptionInfo``) which makes Python keep all + objects referenced from that cycle (including all local variables in the + current frame) alive until the next cyclic garbage collection run. See the + official Python ``try`` statement documentation for more detailed + information. + """ __tracebackhide__ = True if ExpectedException is AssertionError: From c41db8ebbb91780f4d8ad236223ce76be73b7dbe Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 23 Jan 2014 11:38:05 +0100 Subject: [PATCH 3/6] refine contributing text in several places --- CONTRIBUTING.rst | 122 +++++++++++++++++++++++------------------------ runtox.py | 10 ++++ 2 files changed, 71 insertions(+), 61 deletions(-) create mode 100644 runtox.py diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index e1c0c0b3b..71a459633 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -9,6 +9,19 @@ so do not hesitate! Types of contributions ====================== +Report bugs +----------- + +Report bugs at https://bitbucket.org/hpk42/pytest/issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your local setup that might be helpful in troubleshooting, + specifically Python interpreter version, + installed libraries and py.test version. +* Detailed steps to reproduce the bug. + Submit feedback for developers ------------------------------ @@ -24,18 +37,6 @@ We'd also like to hear about your propositions and suggestions. Feel free to * If you have required skills and/or knowledge, we are very happy for pull requests (see below). -Report bugs ------------ - -Report bugs at https://bitbucket.org/hpk42/pytest/issues. - -If you are reporting a bug, please include: - -* Your operating system name and version. -* Any details about your local setup that might be helpful in troubleshooting, - specifically Python interpreter version, - installed libraries and py.test version. -* Detailed steps to reproduce the bug. Fix bugs -------- @@ -65,8 +66,8 @@ py.test could always use more documentation. What exactly is needed? * Docstrings. There's never too much of them. * Blog posts, articles and such -- they're all very appreciated. -Getting started for contributing -================================ +Preparing Pull Requests on Bitbucket +===================================== The primary development platform for py.test is BitBucket. You can find all the issues there and submit pull requests. There is, however, @@ -74,58 +75,59 @@ a `GitHub mirror `__ available, too, although it only allows for submitting pull requests. For a GitHub contribution guide look :ref:`below `. -1. Fork the py.test `repository `__ on BitBucket. +1. Fork the `pytest bitbucket repository `__. It's fine to + use ``pytest`` as your fork repository name because it will live + under your user. -2. Create a local virtualenv (http://www.virtualenv.org/en/latest/):: +.. _virtualenvactivate: + +2. Create and activate a fork-specific virtualenv + (http://www.virtualenv.org/en/latest/):: $ virtualenv pytest-venv - $ cd pytest-venv/ - $ source bin/activate + $ source pytest-venv/bin/activate .. _checkout: -3. Clone your fork locally:: +3. Clone your fork locally and create a branch:: - $ hg clone ssh://hg@bitbucket.org/your_name_here/pytest - -.. _installing-dev-pytest: - -4. Install your local copy into a virtualenv:: - - $ cd pytest/ - $ python setup.py develop - - If that last command complains about not finding the required version - of "py" then you need to use the development pypi repository:: - - $ python setup.py develop -i http://pypi.testrun.org + $ hg clone ssh://hg@bitbucket.org/YOUR_BITBUCKET_USERNAME/pytest + $ cd pytest + $ hg branch .. _testing-pytest: -5. When you're done making changes, check that all of them pass all the tests - (including PEP8 and different Python interpreter versions). First install - ``tox``:: +4. You can now edit your local working copy. To test you need to + install the "tox" tool into your virtualenv:: $ pip install tox - You also need to have Python 2.7 and 3.3 available in your system. Now - running tests is as simple as issuing this one command:: + You need to have Python 2.7 and 3.3 available in your system. Now + running tests is as simple as issuing this command:: - $ tox -e py27,py33 + $ python runtox.py -e py27,py33,flakes - This command will run tests for both Python 2.7 and 3.3, which is a minimum - required to get your patch merged. To run whole test suit issue:: + This command will run tests via the "tox" tool against Python 2.7 and 3.3 + and also perform "flakes" coding-style checks. ``runtox.py`` is + a thin wrapper around ``tox`` which installs from a development package + index where newer (not yet released to pypi) versions of dependencies + (especially ``py``) might be present. - $ tox + To run tests on py27 and pass options (e.g. enter pdb on failure) + to pytest you can do:: -6. Commit your changes and push to BitBucket:: + $ python runtox.py -e py27 -- --pdb - $ hg branch - $ hg add . - $ hg commit -m" + or to only run tests in a particular test module on py33:: + + $ python runtox.py -e py33 -- testing/test_config.py + +5. Commit and push once your tests pass and you are happy with your change(s):: + + $ hg commit -m"" $ hg push -b . -7. Submit a pull request through the BitBucket website: +6. Finally, submit a pull request through the BitBucket website:: source: /pytest branch: @@ -133,34 +135,32 @@ contribution guide look :ref:`below `. target: hpk42/pytest branch: default - .. _contribution-on-github: -What about GitHub? ------------------- + +Preparing Pull Requests on Github +===================================== .. warning:: + Remember that GitHub is **not** a default development platform for py.test and it doesn't include e.g. issue list. -1. Fork the py.test `repository `__ on GitHub. +1. Fork the `pytest github repository `__. -2. Create a local virtualenv (http://www.virtualenv.org/en/latest/):: +2. :ref:`create and activate virtualenv `. - $ virtualenv pytest-venv - $ cd pytest-venv/ +3. Clone your github fork locally and create a branch:: -3. Clone your fork locally:: + $ git clone git@github.com:YOUR_GITHUB_USERNAME/pytest.git + $ cd pytest + $ git branch + $ git checkout - $ git clone git@github.com:your_name_here/pytest.git - -4. :ref:`Install your local copy into a virtualenv ` - and after that :ref:`test your changes `. +4. :ref:`test your changes `. 5. Commit your changes and push to GitHub:: - $ git branch - $ git checkout - $ git add . + $ git add PATH/TO/MODIFIED/FILE # to add changes to staging $ git commit -am"" $ git push origin diff --git a/runtox.py b/runtox.py new file mode 100644 index 000000000..94e80ba4f --- /dev/null +++ b/runtox.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import subprocess +import sys + +if __name__ == "__main__": + subprocess.call(["tox", + "-i", "ALL=https://devpi.net/hpk/dev/", + "--develop",] + sys.argv[1:]) + From ac0b862f8f6804af0224baf769e2d3293d9f8129 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 23 Jan 2014 11:42:20 +0100 Subject: [PATCH 4/6] speak about "pytest" rather than "py.test". Thanks Jurko. --- CONTRIBUTING.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 71a459633..ea7ae1441 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -19,13 +19,13 @@ If you are reporting a bug, please include: * Your operating system name and version. * Any details about your local setup that might be helpful in troubleshooting, specifically Python interpreter version, - installed libraries and py.test version. + installed libraries and pytest version. * Detailed steps to reproduce the bug. Submit feedback for developers ------------------------------ -Do you like py.test? Share some love on Twitter or in your blog posts! +Do you like pytest? Share some love on Twitter or in your blog posts! We'd also like to hear about your propositions and suggestions. Feel free to `submit them as issues `__ and: @@ -59,7 +59,7 @@ features. Write documentation ------------------- -py.test could always use more documentation. What exactly is needed? +pytest could always use more documentation. What exactly is needed? * More complementary documentation. Have you perhaps found something unclear? * Documentation translations. We currently have English and Japanese versions. @@ -69,7 +69,7 @@ py.test could always use more documentation. What exactly is needed? Preparing Pull Requests on Bitbucket ===================================== -The primary development platform for py.test is BitBucket. You can find all +The primary development platform for pytest is BitBucket. You can find all the issues there and submit pull requests. There is, however, a `GitHub mirror `__ available, too, although it only allows for submitting pull requests. For a GitHub @@ -142,7 +142,7 @@ Preparing Pull Requests on Github .. warning:: - Remember that GitHub is **not** a default development platform for py.test + Remember that GitHub is **not** a default development platform for pytest and it doesn't include e.g. issue list. 1. Fork the `pytest github repository `__. From 14a43fffeef4702ec075c3f91e6d7b405810fb49 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 23 Jan 2014 12:18:20 +0100 Subject: [PATCH 5/6] have travis use the devpi index to get the pylib dependency --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e60893f63..1c865fb9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,8 @@ language: python # command to install dependencies install: "pip install -U detox" # # command to run tests -script: detox --recreate +script: detox --recreate -i ALL=https://devpi.net/hpk/dev/ + notifications: irc: - "chat.freenode.net#pytest-dev" From 4e2a820c6a232ed884a205a69d71d1c9d5d0d8ee Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 23 Jan 2014 13:07:28 +0100 Subject: [PATCH 6/6] add Daniel Greensfeld 3-part blog series about pytest --- doc/en/talks.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/en/talks.txt b/doc/en/talks.txt index 58470141b..75b6e4cfa 100644 --- a/doc/en/talks.txt +++ b/doc/en/talks.txt @@ -18,6 +18,9 @@ Basic usage and fixtures: - `pytest introduction from Brian Okken (January 2013) `_ +- `3-part blog series about pytest from Daniel Greenfeld (January + 2014) `_ + - `pycon australia 2012 pytest talk from Brianna Laugher `_ (`video `_, `slides `_, `code `_) - `pycon 2012 US talk video from Holger Krekel `_