Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #1071

pytest-2.4: may better fixtures be with you

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <holger@merlinux.eu>
X-Original-To python-announce-list@python.org
Delivered-To python-announce-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'url:pypi': 0.03; 'parameters': 0.04; 'importing': 0.05; 'output': 0.05; '<>`_': 0.07; 'attribute': 0.07; 'context': 0.07; 'environments': 0.07; 'fixes': 0.07; 'method.': 0.07; 'puts': 0.07; 'remaining': 0.07; 'skip:` 10': 0.07; 'string': 0.09; 'anymore.': 0.09; 'cleanup': 0.09; 'counting': 0.09; 'decorator': 0.09; 'dependency': 0.09; 'doctest': 0.09; 'experimental': 0.09; 'fix.': 0.09; 'generators': 0.09; 'hooks': 0.09; 'iterate': 0.09; 'mixed': 0.09; 'optparse': 0.09; 'parameter': 0.09; 'parsed': 0.09; 'prevents': 0.09; 'spelling': 0.09; 'target,': 0.09; 'variant': 0.09; 'python': 0.11; 'bug': 0.12; 'changes': 0.15; '``import': 0.16; '``yield``': 0.16; 'accepts': 0.16; 'anatoly': 0.16; 'andreas': 0.16; 'arg': 0.16; 'backward': 0.16; 'boolean': 0.16; 'compatible.': 0.16; 'debugging:': 0.16; 'doctests': 0.16; 'easy_install': 0.16; 'errors)': 0.16; 'finalization': 0.16; 'generator.': 0.16; 'internally': 0.16; 'introduces': 0.16; 'invocation': 0.16; 'krekel': 0.16; 'modules.': 0.16; 'node.': 0.16; 'pdb': 0.16; 'pytest': 0.16; 'python2.5': 0.16; 'received:eu': 0.16; 'recognise': 0.16; 'refactoring': 0.16; 'reversed': 0.16; 'skip:` 30': 0.16; 'skip:` 40': 0.16; 'skipping': 0.16; 'slight': 0.16; 'sorting': 0.16; 'specifying': 0.16; 'subject:may': 0.16; 'supported.': 0.16; 'surprises': 0.16; 'test-suite': 0.16; 'to:addr:python-announce-list': 0.16; 'files.': 0.16; 'ignore': 0.16; 'fix': 0.17; 'code.': 0.18; 'module': 0.19; 'items.': 0.19; 'passing': 0.19; 'properly': 0.19; 'skip:p 40': 0.19; 'version.': 0.19; 'examples': 0.20; 'command': 0.22; 'example': 0.22; 'import': 0.22; 'separate': 0.22; 'tests': 0.22; 'print': 0.22; 'install': 0.23; 'header:User-Agent:1': 0.23; 'error': 0.23; 'exists': 0.24; 'helper': 0.24; 'holger': 0.24; 'integrate': 0.24; 'removed.': 0.24; 'replace': 0.24; 'skip:` 20': 0.24; 'specify': 0.24; 'initial': 0.24; 'environment': 0.24; 'options': 0.25; 'script': 0.25; '(see': 0.26; 'changes,': 0.26; 'pass': 0.26; '(for': 0.26; 'skip:" 20': 0.27; 'van': 0.27; 'function': 0.29; 'feature': 0.29; 'generally': 0.29; 'reporting': 0.29; 'errors': 0.30; 'relative': 0.30; 'returned': 0.30; 'sets': 0.30; 'statement': 0.30; 'implicit': 0.31; 'loading': 0.31; 'minor': 0.31; 'python2.7': 0.31; 'consumer': 0.70; 'below.': 0.71; 'apart': 0.72; 'influence': 0.74; 'introduce': 0.78; 'avoids': 0.84; 'characters,': 0.84; 'collection.': 0.84; 'fails,': 0.84; 'features:': 0.84; 'highlights:': 0.84; 'interaction.': 0.84; 'partially': 0.84; 'plugins': 0.84; 'real- life': 0.84; 'rework': 0.84; 'support:': 0.84; 'treating': 0.84; 'subject:you': 0.87; 'favour': 0.91; 'sfxlen:1': 0.91; 'url:latest': 0.91; 'numerous': 0.93
Date Tue, 1 Oct 2013 10:39:51 +0000
From holger krekel <holger@merlinux.eu>
To pytest-dev <pytest-dev@python.org>, Testing in Python <testing-in-python@lists.idyll.org>, python announce <python-announce-list@python.org>
Subject pytest-2.4: may better fixtures be with you
Mail-Followup-To holger krekel <holger@merlinux.eu>, pytest-dev <pytest-dev@python.org>, Testing in Python <testing-in-python@lists.idyll.org>, python announce <python-announce-list@python.org>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.20 (2009-06-14)
X-Mailman-Approved-At Tue, 01 Oct 2013 16:10:35 +0200
X-BeenThere python-announce-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id Announcement-only list for the Python programming language <python-announce-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-announce-list/>
List-Post <mailto:python-announce-list@python.org>
List-Help <mailto:python-announce-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=subscribe>
Approved python-announce-list@python.org
Newsgroups comp.lang.python.announce
Message-ID <mailman.558.1380636636.18130.python-announce-list@python.org> (permalink)
Lines 222
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1380636636 news.xs4all.nl 15921 [2001:888:2000:d::a6]:56745
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python.announce:1071

Show key headers only | View raw


The just released pytest-2.4.0 brings many improvements and numerous 
bug fixes while remaining plugin- and test-suite compatible apart
from a few supposedly very minor incompatibilities.  See below for 
a full list of details.  A few feature highlights:

- new yield-style fixtures `pytest.yield_fixture
  <http://pytest.org/latest/yieldfixture.html>`_, allowing to use
  existing with-style context managers in fixture functions.

- improved pdb support: ``import pdb ; pdb.set_trace()`` now works
  without requiring prior disabling of stdout/stderr capturing.
  Also the ``--pdb`` options works now on collection and internal errors
  and we introduced a new experimental hook for IDEs/plugins to 
  intercept debugging: ``pytest_exception_interact(node, call, report)``.

- shorter monkeypatch variant to allow specifying an import path as
  a target, for example: ``monkeypatch.setattr("requests.get", myfunc)``

- better unittest/nose compatibility: all teardown methods are now only
  called if the corresponding setup method succeeded.

- integrate tab-completion on command line options if you
  have `argcomplete <http://pypi.python.org/pypi/argcomplete>`_ 
  configured.

- allow boolean expression directly with skipif/xfail
  if a "reason" is also specified.

- a new hook ``pytest_load_initial_conftests`` allows plugins like
  `pytest-django <http://pypi.python.org/pypi/pytest-django>`_ to
  influence the environment before conftest files import ``django``.

- reporting: color the last line red or green depending if
  failures/errors occured or everything passed.

The documentation has been updated to accomodate the changes, 
see `http://pytest.org <http://pytest.org>`_ 

To install or upgrade pytest::

    pip install -U pytest # or
    easy_install -U pytest


**Many thanks to all who helped, including Floris Bruynooghe, 
Brianna Laugher, Andreas Pelme, Anthon van der Neut, Anatoly Bubenkoff, 
Vladimir Keleshev, Mathieu Agopian, Ronny Pfannschmidt, Christian
Theunert and many others.**

may passing tests be with you,

holger krekel

Changes between 2.3.5 and 2.4
-----------------------------------

known incompatibilities:

- if calling --genscript from python2.7 or above, you only get a
  standalone script which works on python2.7 or above.  Use Python2.6
  to also get a python2.5 compatible version.

- all xunit-style teardown methods (nose-style, pytest-style,
  unittest-style) will not be called if the corresponding setup method failed,
  see issue322 below.

- the pytest_plugin_unregister hook wasn't ever properly called
  and there is no known implementation of the hook - so it got removed.

- pytest.fixture-decorated functions cannot be generators (i.e. use
  yield) anymore.  This change might be reversed in 2.4.1 if it causes
  unforeseen real-life issues.  However, you can always write and return
  an inner function/generator and change the fixture consumer to iterate
  over the returned generator.  This change was done in lieu of the new
  ``pytest.yield_fixture`` decorator, see below.

new features:

- experimentally introduce a new ``pytest.yield_fixture`` decorator
  which accepts exactly the same parameters as pytest.fixture but
  mandates a ``yield`` statement instead of a ``return statement`` from
  fixture functions.  This allows direct integration with "with-style"
  context managers in fixture functions and generally avoids registering
  of finalization callbacks in favour of treating the "after-yield" as
  teardown code.  Thanks Andreas Pelme, Vladimir Keleshev, Floris
  Bruynooghe, Ronny Pfannschmidt and many others for discussions.

- allow boolean expression directly with skipif/xfail
  if a "reason" is also specified.  Rework skipping documentation
  to recommend "condition as booleans" because it prevents surprises
  when importing markers between modules.  Specifying conditions
  as strings will remain fully supported.

- reporting: color the last line red or green depending if
  failures/errors occured or everything passed.  thanks Christian
  Theunert.

- make "import pdb ; pdb.set_trace()" work natively wrt capturing (no
  "-s" needed anymore), making ``pytest.set_trace()`` a mere shortcut.

- fix issue181: --pdb now also works on collect errors (and 
  on internal errors) .  This was implemented by a slight internal 
  refactoring and the introduction of a new hook 
  ``pytest_exception_interact`` hook (see next item).

- fix issue341: introduce new experimental hook for IDEs/terminals to 
  intercept debugging: ``pytest_exception_interact(node, call, report)``.

- new monkeypatch.setattr() variant to provide a shorter
  invocation for patching out classes/functions from modules:

     monkeypatch.setattr("requests.get", myfunc)

  will replace the "get" function of the "requests" module with ``myfunc``.

- fix issue322: tearDownClass is not run if setUpClass failed. Thanks
  Mathieu Agopian for the initial fix.  Also make all of pytest/nose
  finalizer mimick the same generic behaviour: if a setupX exists and
  fails, don't run teardownX.  This internally introduces a new method
  "node.addfinalizer()" helper which can only be called during the setup
  phase of a node.

- simplify pytest.mark.parametrize() signature: allow to pass a
  CSV-separated string to specify argnames.  For example: 
  ``pytest.mark.parametrize("input,expected",  [(1,2), (2,3)])``
  works as well as the previous:
  ``pytest.mark.parametrize(("input", "expected"), ...)``.

- add support for setUpModule/tearDownModule detection, thanks Brian Okken.

- integrate tab-completion on options through use of "argcomplete".
  Thanks Anthon van der Neut for the PR.

- change option names to be hyphen-separated long options but keep the
  old spelling backward compatible.  py.test -h will only show the
  hyphenated version, for example "--collect-only" but "--collectonly"
  will remain valid as well (for backward-compat reasons).  Many thanks to
  Anthon van der Neut for the implementation and to Hynek Schlawack for
  pushing us.

- fix issue 308 - allow to mark/xfail/skip individual parameter sets
  when parametrizing.  Thanks Brianna Laugher.

- call new experimental pytest_load_initial_conftests hook to allow
  3rd party plugins to do something before a conftest is loaded.

Bug fixes:

- fix issue358 - capturing options are now parsed more properly 
  by using a new parser.parse_known_args method.

- pytest now uses argparse instead of optparse (thanks Anthon) which 
  means that "argparse" is added as a dependency if installing into python2.6
  environments or below.

- fix issue333: fix a case of bad unittest/pytest hook interaction.

- PR27: correctly handle nose.SkipTest during collection.  Thanks
  Antonio Cuni, Ronny Pfannschmidt.

- fix issue355: junitxml puts name="pytest" attribute to testsuite tag.

- fix issue336: autouse fixture in plugins should work again.

- fix issue279: improve object comparisons on assertion failure
  for standard datatypes and recognise collections.abc.  Thanks to
  Brianna Laugher and Mathieu Agopian.

- fix issue317: assertion rewriter support for the is_package method

- fix issue335: document py.code.ExceptionInfo() object returned
  from pytest.raises(), thanks Mathieu Agopian.

- remove implicit distribute_setup support from setup.py.

- fix issue305: ignore any problems when writing pyc files.

- SO-17664702: call fixture finalizers even if the fixture function
  partially failed (finalizers would not always be called before)

- fix issue320 - fix class scope for fixtures when mixed with
  module-level functions.  Thanks Anatloy Bubenkoff.

- you can specify "-q" or "-qq" to get different levels of "quieter"
  reporting (thanks Katarzyna Jachim)

- fix issue300 - Fix order of conftest loading when starting py.test
  in a subdirectory.

- fix issue323 - sorting of many module-scoped arg parametrizations

- make sessionfinish hooks execute with the same cwd-context as at
  session start (helps fix plugin behaviour which write output files 
  with relative path such as pytest-cov)

- fix issue316 - properly reference collection hooks in docs

- fix issue 306 - cleanup of -k/-m options to only match markers/test
  names/keywords respectively.  Thanks Wouter van Ackooy.

- improved doctest counting for doctests in python modules -- 
  files without any doctest items will not show up anymore
  and doctest examples are counted as separate test items.
  thanks Danilo Bellini.

- fix issue245 by depending on the released py-1.4.14
  which fixes py.io.dupfile to work with files with no
  mode. Thanks Jason R. Coombs.

- fix junitxml generation when test output contains control characters,
  addressing issue267, thanks Jaap Broekhuizen 

- fix issue338: honor --tb style for setup/teardown errors as well.  Thanks Maho.

- fix issue307 - use yaml.safe_load in example, thanks Mark Eichin.

- better parametrize error messages, thanks Brianna Laugher

- pytest_terminal_summary(terminalreporter) hooks can now use
  ".section(title)" and ".line(msg)" methods to print extra 
  information at the end of a test run.

Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread


Thread

pytest-2.4: may better fixtures be with you holger krekel <holger@merlinux.eu> - 2013-10-01 10:39 +0000

csiph-web