Skip to content

pytest discovery ignores per-subfolder pytest.ini / pyproject.toml [tool.pytest.ini_options] in monorepo (Windows) #26023

Description

@chirag127

Environment

  • OS: Windows 11 Enterprise
  • VS Code: 1.104.x
  • Python extension: latest
  • pytest: 8.x
  • Repo layout: monorepo where each sub-package has its own pyproject.toml with [tool.pytest.ini_options] (different testpaths, addopts, pythonpath per package)

Problem

In a monorepo, pytest's rootdir resolution walks up from the file being discovered. When VS Code's test runner invokes pytest from the workspace root (not from each sub-package directory), pytest finds the root-level pyproject.toml (if any) or no config, and uses rootdir = <workspace root>. This means:

  1. [tool.pytest.ini_options] in packages/api/pyproject.toml is ignored — its testpaths, pythonpath, and addopts don't apply.
  2. packages/api/tests/ may not even be collected because testpaths in the root config doesn't include it.
  3. Tests that pass in a terminal (cd packages/api && pytest) fail in VS Code's test runner with import errors because pythonpath = ["src"] (relative to packages/api) is not applied.

Expected

Provide a way to configure per-subfolder pytest invocation roots, such that VS Code runs pytest for packages/api/** with cwd=packages/api, picking up that package's pyproject.toml.

Possible configuration:

"python.testing.pytestRoots": [
  { "path": "packages/api", "config": "packages/api/pyproject.toml" },
  { "path": "packages/core", "config": "packages/core/pyproject.toml" }
]

Or: auto-discover all pyproject.toml files with [tool.pytest.ini_options] under the workspace and create a separate pytest invocation per rootdir.

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions