Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions doc/en/proposals/importmode_root_spec.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
:orphan:

===================================
PROPOSAL: Parametrize with fixtures
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to adjust this

===================================

.. warning::

This document outlines a proposal around creating a new import mode that supports pep420 and
supports the dissonance between installed and editable installed


Problem
=======

test module discovery in pytest currently is is pre-pep40 and create pains for users
by adding anything things to sys.path and creating easy conflicts in sys.modules
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test module discovery in pytest currently is is pre-pep40 and create pains for users
by adding anything things to sys.path and creating easy conflicts in sys.modules
Test module discovery in pytest currently is is pre-PEP420 and creates pain for users
by adding things to ``sys.path`` and creating easy conflicts in ``sys.modules``.


Additionally this will not solve the dissonance between doctest tests vs installed modules

The importlib mode in contrast breaks all kinds of expectations by importing test modules in a magical way
that breaks relative imports and leaves them out of ``sys.modules``


Proposed Solution
=================

A new import mode take a definition of import roots.

a import root is either a folder in the worktree that will no be installed,
or a folder that will be installed either normally or editable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is installation done? Like pytest will install to the venv with pip?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users Will have to manage install, pytest should never do that part


In any case pytest will collect the file tree in the working directory.

If normal install us used and the content of the imported file differs from the working directory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If normal install us used and the content of the imported file differs from the working directory,
If normal install is used and the content of the imported file differs from the working directory,

pytest will fail collection with a "ContentMissmatch" error.

When import roots are specified, nothing will be added to sys.path
instead installable content will rely in installs, and local content will create namespace packages that limit the path of subitems

everything else will be discovered using normal imports




.. code-block::

# contents of pytest.ini
[pytest]
import-roots =
testing/ local
src/mypkg installed as mypkg
# alterntively
src/ installed

## todo testcases

* handle install vs editable install

* when installed - imported name will differe from name in soruce tree
fail collection when content differs
(optional strictly check all files/missing files)
* when installed editable - import using the right name

* when not installed:

* testing folders
* if no __init__.py -> create fake namespace, use it for importing
* if __init__.py -> create normal package, dont change sys.path

* ensure each folder gets a collection package