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:
[tool.pytest.ini_options] in packages/api/pyproject.toml is ignored — its testpaths, pythonpath, and addopts don't apply.
packages/api/tests/ may not even be collected because testpaths in the root config doesn't include it.
- 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:
Or: auto-discover all pyproject.toml files with [tool.pytest.ini_options] under the workspace and create a separate pytest invocation per rootdir.
Related
Environment
pyproject.tomlwith[tool.pytest.ini_options](differenttestpaths,addopts,pythonpathper package)Problem
In a monorepo, pytest's
rootdirresolution 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-levelpyproject.toml(if any) or no config, and usesrootdir = <workspace root>. This means:[tool.pytest.ini_options]inpackages/api/pyproject.tomlis ignored — itstestpaths,pythonpath, andaddoptsdon't apply.packages/api/tests/may not even be collected becausetestpathsin the root config doesn't include it.cd packages/api && pytest) fail in VS Code's test runner with import errors becausepythonpath = ["src"](relative topackages/api) is not applied.Expected
Provide a way to configure per-subfolder pytest invocation roots, such that VS Code runs pytest for
packages/api/**withcwd=packages/api, picking up that package'spyproject.toml.Possible configuration:
Or: auto-discover all
pyproject.tomlfiles with[tool.pytest.ini_options]under the workspace and create a separate pytest invocation perrootdir.Related