catalyst-cooperative / pudl

The Public Utility Data Liberation Project provides analysis-ready energy system data to climate advocates, researchers, policymakers, and journalists.
https://catalyst.coop/pudl
MIT License
453 stars 105 forks source link

Stop ignoring test directory passed to pytest. #3610

Closed jdangerx closed 1 month ago

jdangerx commented 1 month ago

Overview

Closes #3609 .

When passing a path to pytest, the path was being ignored - which meant that it would collect all our tests. However, when passing in other command line arguments like --collect-only, or -k, pytest would behave correctly again.

The problem was that the first non-named argument we passed in was getting swallowed... because we defined --cov as the last opt in tool.pytest.ini_options.addopts. Since --cov takes an optional value, when we inject the opts from addopts, we get:

pytest --verbose ... --cov <path>

Which treats <path> as the path to measure coverage for. Instead of as the path to look for tests in.

pytest --co <path> gets expanded into pytest --verbose ... --cov --co <path> which then gets parsed correctly since we don't think that --co is a coverage path.

So - reordering the args fixes the problem. In a brittle way, but that's what comments are for :sob:.

Testing

How did you make sure this worked? How can a reviewer verify this?

Ran pytest test/unit/transform and saw that it only tried to collect 64 tests instead of 2103.

# To-do list
- [ ] Ensure docs build, unit & integration tests, and test coverage pass locally with `make pytest-coverage` (otherwise the merge queue may reject your PR)