[Distutils] zope.testrunner behavior change
Barry Warsaw
barry at python.org
Mon Aug 30 17:02:51 CEST 2010
On Aug 30, 2010, at 10:08 AM, Gary Poster wrote:
>> So my question is: would it make sense to be able to ask
>> zope.testrunner where it's running from, so that I don't have to
>> hard code cwd? Better still would be a function in z.t that I could
>> call that would get me back to root directory. E.g. something like:
>>
>> ... cwd=zope.testrunner.root_directory()
>>
>> Thoughts? It's not that big of a deal, but I don't like that my
>> test relies on undocumented zope.testrunner behavior.
>
>I think it is more a buildout question, and buildout does offer a way
>of getting that information when you are writing scripts. ${buildout:
>directory} is available in the .cfg files for script initialization
>(stuff it in an environ variable, maybe?), and of course can be also
>used in templating solutions like z3c.recipe.filetemplate.
>
>Is that sufficient for a solution?
It is! I've already hooked in an initialization key in the [test] section's
use of zc.recipe.testrunner in my buildout.cfg, so it was fairly easy to put
this together. Below is the relevant code, for the archives.
Thanks Gary!
-Barry
-----buildout.cfg
[test]
recipe = zc.recipe.testrunner
eggs =
mailman
defaults = '--tests-pattern ^tests --exit-with-status'.split()
# Hack in extra arguments to zope.testrunner.
initialization = from mailman.testing.layers import ConfigLayer;
ConfigLayer.enable_stderr();
ConfigLayer.set_root_directory('${buildout:directory}')
-----src/mailman/testing/layers.py
class ConfigLayer:
# ...
@classmethod
def set_root_directory(cls, directory):
"""Set the directory at the root of our source tree.
zc.recipe.testrunner runs from parts/test/working-directory, but
that's actually changed over the life of the package. Some tests
care, e.g. because they need to find our built-out bin directory.
Fortunately, buildout can give us this information. See the
`buildout.cfg` file for where this method is called.
"""
cls.root_directory = directory
-----src/mailman/app/docs/hooks.txt
>>> def call():
... proc = subprocess.Popen(
... 'bin/mailman lists --domain ignore -q'.split(),
... cwd=ConfigLayer.root_directory,
... env=dict(MAILMAN_CONFIG_FILE=config_path,
... PYTHONPATH=config_directory),
... stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20100830/eb3fd3fa/attachment.pgp>
More information about the Distutils-SIG
mailing list