[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-distutils-sig
Subject:    Re: [Distutils] zope.testrunner behavior change
From:       Barry Warsaw <barry () python ! org>
Date:       2010-08-30 15:02:51
Message-ID: 20100830110251.0e66e445 () heresy
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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)


["signature.asc" (application/pgp-signature)]

_______________________________________________
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic