Skip to content

pytest (doctests) unable to recognize the root package #1

@jaraco

Description

@jaraco

Another challenge I've encountered pertains to running tests, namely doctests. The problem with running doctests in a shallow repo is that relative references are no longer viable. Consider in coherent.build (0.4.0):

# __init__.py

from . import discovery

Although the discovery module exists alongside __init__.py and both will be/are found in coherent/build after installation, pytest "discovers" __init__.py as a plain module and not in the context of coherent.build, so fails thus:

__________________________________________________________ ERROR collecting __init__.py __________________________________________________________
ImportError while importing test module '/Users/jaraco/code/coherent-oss/coherent.build/__init__.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
__init__.py:32: in <module>
    from . import discovery
E   ImportError: attempted relative import with no known parent package

Originally posted by @jaraco in coherent-oss/system#1

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions