Skip to content

Pytest default src layout tweak #309

@rnickle

Description

@rnickle

Claudio,

Thank you very much for this comprehensive article, which I discovered from a recent Talk Python to Me podcast (362).

I was struck by the use of src layout, which I have seen before but did not understand. I immediately tried to adopt it for a
small project, but was struck that if I created a blank project with src layout, pytest was not working by default.

For example:

$ poetry new --name rnickle_template --src rnickle_template
$ ls
README.rst  poetry.lock  pyproject.toml  src  tests
$ pytest | grep ^E
E   ModuleNotFoundError: No module named 'rnickle_template'
ERROR tests/test_rnickle_template.py

There's an easy fix:

$ touch src/conftest.py
$ pytest
[ redacted ]
= 1 passed in 0.39s =

Or in pytest >= 7:

[tool.pytest.ini_options]
pythonpath = [
  "src"
]

Perhaps we can add a comment about that to the setup page?

Thanks,

Rick

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions