Skip to content

✨ feat(config): add platform-dependent factor support#3779

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:feature/platform-factors-2092
Feb 19, 2026
Merged

✨ feat(config): add platform-dependent factor support#3779
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:feature/platform-factors-2092

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

Managing cross-platform projects required creating separate test environments for each platform (like task-linux, task-darwin, task-win32) or using the platform configuration option which skips entire environments when the regex doesn't match. Neither approach allowed a single environment to run different commands based on the execution platform. 🔧

This change injects sys.platform as an implicit factor available to all environments. Platform values like linux, darwin, and win32 become automatically available alongside factors from the environment name, enabling natural conditional configuration that adapts at runtime. Users can now write linux: pytest or win32: mypy in a single environment without encoding the platform in the environment name.

The implementation adds one line to filter_for_env() in src/tox/config/loader/ini/factor.py to include sys.platform in the factor set. This leverages the existing factor filtering infrastructure without requiring changes to how factors are parsed or matched. ✨

Resolves #2092

@gaborbernat gaborbernat marked this pull request as draft February 19, 2026 19:59
@gaborbernat gaborbernat force-pushed the feature/platform-factors-2092 branch 5 times, most recently from 3b3e25f to b1db9b8 Compare February 19, 2026 21:22
Users could not write platform-specific configuration without encoding the
platform in environment names (e.g., py313-linux, py313-darwin). This forced
duplication of environment definitions and made cross-platform projects harder
to maintain. TOML users also lacked any way to use factor-based filtering,
which was only available in INI configurations.

Added automatic platform factor support by injecting sys.platform into the
factor set for all environments. In INI, this enables inline factor syntax like
"linux: pytest" or "!win32: uvloop". In TOML, extended conditional expressions
(added in 4.40) to support factor.NAME lookups alongside env.VAR, enabling
conditions like "factor.linux" or "factor.django50 and not env.CI".

Both formats now have feature parity for factor-based configuration filtering,
with platform automatically available as an implicit factor in any environment
without requiring it in the environment name.
@gaborbernat gaborbernat force-pushed the feature/platform-factors-2092 branch from a21a3af to d7ae712 Compare February 19, 2026 21:29
@gaborbernat gaborbernat marked this pull request as ready for review February 19, 2026 22:02
@gaborbernat gaborbernat merged commit 97cf6e6 into tox-dev:main Feb 19, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specifying a single testenv with platform-dependent commands

1 participant