Nosetest including unwanted parent directories

后端 未结 1 1334
无人共我
无人共我 2021-01-17 23:34

I\'m trying to limit nosetests to a specific directory, however during the test run it\'s including the parent directories of the dir I\'m targetting and in doing so throws

相关标签:
1条回答
  • 2021-01-17 23:58

    I suppose that you are expecting the following behavior.

    nose.importer: DEBUG: Add path /projects/myproject
    nose.importer: DEBUG: insert /projects/myproject into sys.path
    

    Why not try a --match or an --exclude pattern to restrict the tests set ?

    Try:

    --exclude myproject/myproject
    

    I check the source code of nose.importer : nose recursivly add_path the parents packages of specs. I think that you cannot bypass this unless you create a specific importer... I do not not know if this is possible this the nose API.

    def add_path(path, config=None):
        """Ensure that the path, or the root of the current package (if
        path is in a package), is in sys.path.
        """
    
        # FIXME add any src-looking dirs seen too... need to get config for that
    
        log.debug('Add path %s' % path)    
        if not path:
            return []
        added = []
        parent = os.path.dirname(path)
        if (parent
            and os.path.exists(os.path.join(path, '__init__.py'))):
            added.extend(add_path(parent, config))
        elif not path in sys.path:
            log.debug("insert %s into sys.path", path)
            sys.path.insert(0, path)
            added.append(path)
        if config and config.srcDirs:
            for dirname in config.srcDirs:
                dirpath = os.path.join(path, dirname)
                if os.path.isdir(dirpath):
                    sys.path.insert(0, dirpath)
                    added.append(dirpath)
        return added
    
    
    def remove_path(path):
        log.debug('Remove path %s' % path)
        if path in sys.path:
            sys.path.remove(path)
    
    0 讨论(0)
提交回复
热议问题