Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Add a doctest that works without z.a.testing.
Browse files Browse the repository at this point in the history
This is a stripped-down version of setupininit.txt. It requires that
no working zope.app.testing is installed.

Why another doctest? Turned out, that turning this doctest
('setupininit.txt') into a regular Python test, would be even more
complex. Also conditional doctest parts (i.e.: parts of a doctest file
that are only run if a certain condition is met) seem not to be
possible. At least I found no (easily readable) way to write something
like:

  >>> if cond:
  ...   run_one_test()
  result of run_one_test

  >>> if not cond:
  ...   run_other_test()
  result of run_other_test.

where one of the results would be ignored. Any hints would be welcome.
  • Loading branch information
ulif committed May 9, 2015
1 parent bcdecdc commit 709c498
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/z3c/testsetup/tests/setupininit_nonfunctional.txt
@@ -0,0 +1,43 @@
Setting up tests in packages __init__.py
----------------------------------------

.. warning:: The following works only *without* working zope.app.testing!
It is a stripped-down version of `setupininit.txt`.

We can also setup tests in packages' __init__ modules. We defined such
a test setup in the cave package::

>>> import os
>>> import z3c.testsetup
>>> pkgpath = os.path.dirname(z3c.testsetup.__file__)
>>> cavepath = os.path.join(pkgpath, 'tests', 'cave')

The setup looks like this::

>>> setupfile = os.path.join(cavepath, 'tests', '__init__.py')
>>> print(open(setupfile).read())
# this is a package that contains a testsetup.
#
# To let it be found by the testrunner, you must call the testrunner
# with the approriate options set.
import z3c.testsetup
test_suite = z3c.testsetup.register_all_tests('z3c.testsetup.tests.cave')

Now we run this test, requiring `__init__` as the test-file-pattern
for the testrunner::

>>> import sys
>>> defaults = [
... '--path', cavepath,
... '--tests-pattern', '^tests$',
... '--test-file-pattern', '__init__',
... ]
>>> sys.argv = [sys.argv[0]]
>>> from z3c.testsetup import testrunner
>>> testrunner.run(defaults)
Running zope.testrunner.layer.UnitTests tests:
Set up zope.testrunner.layer.UnitTests in 0.000 seconds.
Ran 2 tests with 0 failures and 0 errors in 0.003 seconds.
Tearing down left over layers:
Tear down zope.testrunner.layer.UnitTests in 0.000 seconds.
False

0 comments on commit 709c498

Please sign in to comment.