Skip to content

Comments

pytest: rework conftest.py to support solver/writer marker expressions#3854

Merged
jsiirola merged 14 commits intoPyomo:mainfrom
jsiirola:pytest-solver-test-filter
Feb 18, 2026
Merged

pytest: rework conftest.py to support solver/writer marker expressions#3854
jsiirola merged 14 commits intoPyomo:mainfrom
jsiirola:pytest-solver-test-filter

Conversation

@jsiirola
Copy link
Member

@jsiirola jsiirola commented Feb 18, 2026

Fixes # .

Summary/Motivation:

Pyomo's existing pytest configuration supports marking solver tests using pytest.mark.solver(name), and then running those tests using a custom --solver name command line argument. However, the test selection was done by skipping tests at runtime and not deselecting the tests after collection. Further, the markers could not be used in "normal" marker expressions (because pytest does not support accessing positional arguments in marker expressions).

This PR redesigns how we handle solver markers:

  • the positional argument is mapped to a keyword argument (id). This enables using markers expressions like solver(id='highs') to select tests based on the solver marker.
  • an additional keyword argument (vendor) is also defined using a substring of id up to, but not including the first underscore. This supports selecting "all" tests for a vendor. For example solver(vendor='gurobi') will match gurobi, gurobi_direct, and gurobi_persistent solver markers.
  • the --solver command line option is now translated into a marker expression (instead of relying on skipping tests at runtime)
  • move the solver marker definition into the pyproject.toml (with all the other markers)

In addition, this PR:

  • adds a writer marker that works analogously to the solver marker
  • removes a number of unused pytest markers from pyproject.toml
  • propagates the use of the solver marker through the solver tests in pyomo.solvers and pyomo.contrib.solver
  • found a way to mark tests generated by paarameterized.expand

Changes proposed in this PR:

  • (see above)

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 90.32258% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.63%. Comparing base (5852a20) to head (c2ce299).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
conftest.py 90.32% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3854      +/-   ##
==========================================
+ Coverage   89.59%   89.63%   +0.04%     
==========================================
  Files         905      905              
  Lines      106006   106014       +8     
==========================================
+ Hits        94974    95030      +56     
+ Misses      11032    10984      -48     
Flag Coverage Δ
builders 29.13% <87.09%> (+0.02%) ⬆️
default 85.95% <90.32%> (?)
expensive 35.60% <87.09%> (?)
linux 86.92% <ø> (-2.25%) ⬇️
linux_other 86.92% <ø> (ø)
oldsolvers 32.10% <87.09%> (+2.23%) ⬆️
osx 83.09% <ø> (ø)
win 85.15% <ø> (-0.01%) ⬇️
win_other 85.15% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jsiirola jsiirola merged commit 35424f2 into Pyomo:main Feb 18, 2026
64 of 65 checks passed
@jsiirola jsiirola deleted the pytest-solver-test-filter branch February 18, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants