[py-dev] py.test and darcs

Michael Twomey micktwomey at gmail.com
Mon May 2 15:07:13 CEST 2005


Hi,

I've been setting up a new pet project using py.test as the testing
framework, and darcs as the scm. I've hit a problem after my first
"darcs record" (darcs checkin). Darcs keeps a copy of the checked out
originals under a _darcs directory in the root of the source tree,
which causes py.test some confusion during the collect phase, since it
has duplicate python modules to contend with.

Ideally I'd like py.test to ignore _darcs (and I think {arch} for GNU
arch too) out of the box, but is there a way to twist conftest.py's
arm to make it ignore these directories?

A simple workaround is to specify my package directly. Of course, that
only works with my layout, I keep all the python files together in one
place.

(Oh yeah, py.test is very nice to use, keep up the good work, can't
wait for the doctest stuff :) )

cheers,
  Michael


My layout (don't ask about the whimsical name please):

topdir/applepie/..python.modules...
topdir/applepie/tests/test_*.py
topdir/_darcs/current/...all.the.files...
topdir/_darcs/current/applepie/tests/test_*.py

The output of a collectonly on a fresh checkout:

(er, don't take the Junk directory below the wrong way, I put all my
source tarballs and anonymous checkouts in there)

hamtoro:~/Projects/ApplePie/applepie_2 mick$ py.test --collectonly
inserting into sys.path: /Users/mick/Junk/py-dist
======================================================== test process
starts ========================================================testing-mode:
inprocess
executable:   /usr/local/bin/python  (2.4.1-final-0)
using py lib: /Users/mick/Junk/py-dist/py <rev 11775>

<Directory 'applepie_2'>
    <Directory '_darcs'>
        <Directory 'checkpoints'>
        <Directory 'current'>
            <Directory 'applepie'>
                <Directory 'docs'>
                <Directory 'tests'>
                    <Module 'test_docs.py'>
                        <Generator 'test_docs'>
                            <Function '[0]'>
                    <Module 'test_files.py'>
                        <Function 'test_files_docs'>
            <Directory 'diagrams'>
            <Directory 'scripts'>
        <Directory 'inventories'>
        <Directory 'patches'>
        <Directory 'prefs'>
    <Directory 'applepie'>
        <Directory 'docs'>
        <Directory 'tests'>
            <Module 'test_docs.py'>
            <Module 'test_files.py'>
    <Directory 'diagrams'>
    <Directory 'scripts'>

_____________________________________________________________________________________________________________________________________
    def runtraced(self, colitem):
        if self.shouldclose(): 
            raise Exit, "received external close signal" 
    
        outcome = capture = None 
        # XXX capturing output even for collectors? 
        if not self.config.option.nocapture: 
            if isinstance(colitem, py.test.Item) or not
self.config.option.usepdb:
                capture = SimpleOutErrCapture() 
        needfinish = False
        try: 
            self.start(colitem)
            needfinish = True
            try:
                if colitem._stickyfailure: 
                    raise colitem._stickyfailure 
>               outcome = self.run(colitem) 

[/Users/mick/Junk/py-dist/py/test/session.py:75]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def run(self, colitem): 
        if self.config.option.collectonly and isinstance(colitem,
py.test.Item):
            return 
>       res = colitem.run() 

[/Users/mick/Junk/py-dist/py/test/session.py:99]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def run(self): 
        l = []
>       for name in dir(self.obj): 

[/Users/mick/Junk/py-dist/py/test/collect.py:261]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def obj(self): 
        try: 
            return self._obj    
        except AttributeError:
>           self._obj = obj = self.fspath.pyimport() 

[/Users/mick/Junk/py-dist/py/test/collect.py:288]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def pyimport(self, modname=None, ensuresyspath=True): 
        """ return path as an imported python module. 
            if modname is None, look for the containing package 
            and construct an according module name. 
            The module will be put/looked up in sys.modules. 
        """ 
        if not self.check(): 
            raise py.error.ENOENT(self) 
        #print "trying to import", self
        pkgpath = None
        if modname is None: 
            pkgpath = self.pypkgpath()
            if pkgpath is not None: 
                if ensuresyspath: 
                    self._prependsyspath(pkgpath.dirpath())
                pkg = __import__(pkgpath.basename, None, None, [])
E               assert py.path.local(pkg.__file__).relto(pkgpath) 
>               assert ''
                 +  where '' =
local('/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc').relto(local('/Users/mick/Projects/ApplePie/applepie_2/applepie'))
                 +    where
local('/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc')
= <class 'py.path.local'>('/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc')
                 +      where <class 'py.path.local'> = <Module 'py.path'>.local
                 +        where <Module 'py.path'> = py.path
                 +      and  
'/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc'
= <module 'applepie' from
'/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc'>.__file__

[/Users/mick/Junk/py-dist/py/path/local/local.py:366]
[testcode  : /Users/mick/Projects/ApplePie/applepie_2/applepie/tests/test_docs.py:2147483648]
[modulepath: ]
_____________________________________________________________________________________________________________________________________
    def runtraced(self, colitem):
        if self.shouldclose(): 
            raise Exit, "received external close signal" 
    
        outcome = capture = None 
        # XXX capturing output even for collectors? 
        if not self.config.option.nocapture: 
            if isinstance(colitem, py.test.Item) or not
self.config.option.usepdb:
                capture = SimpleOutErrCapture() 
        needfinish = False
        try: 
            self.start(colitem)
            needfinish = True
            try:
                if colitem._stickyfailure: 
                    raise colitem._stickyfailure 
>               outcome = self.run(colitem) 

[/Users/mick/Junk/py-dist/py/test/session.py:75]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def run(self, colitem): 
        if self.config.option.collectonly and isinstance(colitem,
py.test.Item):
            return 
>       res = colitem.run() 

[/Users/mick/Junk/py-dist/py/test/session.py:99]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def run(self): 
        l = []
>       for name in dir(self.obj): 

[/Users/mick/Junk/py-dist/py/test/collect.py:261]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def obj(self): 
        try: 
            return self._obj    
        except AttributeError:
>           self._obj = obj = self.fspath.pyimport() 

[/Users/mick/Junk/py-dist/py/test/collect.py:288]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def pyimport(self, modname=None, ensuresyspath=True): 
        """ return path as an imported python module. 
            if modname is None, look for the containing package 
            and construct an according module name. 
            The module will be put/looked up in sys.modules. 
        """ 
        if not self.check(): 
            raise py.error.ENOENT(self) 
        #print "trying to import", self
        pkgpath = None
        if modname is None: 
            pkgpath = self.pypkgpath()
            if pkgpath is not None: 
                if ensuresyspath: 
                    self._prependsyspath(pkgpath.dirpath())
                pkg = __import__(pkgpath.basename, None, None, [])
E               assert py.path.local(pkg.__file__).relto(pkgpath) 
>               assert ''
                 +  where '' =
local('/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc').relto(local('/Users/mick/Projects/ApplePie/applepie_2/applepie'))
                 +    where
local('/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc')
= <class 'py.path.local'>('/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc')
                 +      where <class 'py.path.local'> = <Module 'py.path'>.local
                 +        where <Module 'py.path'> = py.path
                 +      and  
'/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc'
= <module 'applepie' from
'/Users/mick/Projects/ApplePie/applepie_2/_darcs/current/applepie/__init__.pyc'>.__file__

[/Users/mick/Junk/py-dist/py/path/local/local.py:366]
[testcode  : /Users/mick/Projects/ApplePie/applepie_2/applepie/tests/test_files.py:2147483648]
[modulepath: ]
_____________________________________________________________________________________________________________________________________=============================================
tests finished: 2 failed in 0.91 seconds
=============================================



And specifying my package:

hamtoro:~/Projects/ApplePie/applepie_2 mick$ py.test applepie --collect
inserting into sys.path: /Users/mick/Junk/py-dist
======================================================== test process
starts ========================================================testing-mode:
inprocess
executable:   /usr/local/bin/python  (2.4.1-final-0)
using py lib: /Users/mick/Junk/py-dist/py <rev 11775>

<Directory 'applepie'>
    <Directory 'docs'>
    <Directory 'tests'>
        <Module 'test_docs.py'>
            <Generator 'test_docs'>
                <Function '[0]'>
        <Module 'test_files.py'>
            <Function 'test_files_docs'>

================================================= tests finished:  in
0.37 seconds =================================================


More information about the py-dev mailing list