Fix relative ordering in a complex transitive cases#242
Conversation
apply_relative_constraints() unconditionally rebuilt sorted_list as start_pinned + sorted_middle + end_pinned, discarding the unordered items that sort_numbered_items() had interspersed between numbered items in sparse ordering mode. Early-return when there are no relative or dependency marks to preserve the layout produced by sort_numbered_items(). Fixes 5 sparse ordering tests.
for more information, see https://pre-commit.ci
|
Thanks! I will have a closer look at this, though this may take some time (just back from traveling). |
|
|
||
| pytest-order emits a WARNING for each such impossible constraint and preserves | ||
| the absolute ordinal positions unchanged. | ||
| """ |
There was a problem hiding this comment.
This changes the current behavior, which was intentional. Explicit dependencies between tests shall be prioritized over ordinal sorting - I still think that makes sense.
Can you elaborate why you want to change this?
There was a problem hiding this comment.
I was just in the mindset of "all ordering shall be satisfied", and didn't read the docs that deep. Wouldn't have made it a requirement.
There was a problem hiding this comment.
I think using topological sorting still makes sense?
I'll rework the changes according to the design decision, likely next week.
There was a problem hiding this comment.
...reworked.
|
Pushed a new version. It looks decent to me. |
| absolute ordinal markers (`index`, `first`, `last`, …); a conflicting ordinal | ||
| position is relaxed instead of dropping the relative marker | ||
| - transitive relative chains are resolved as a single globally consistent order | ||
|
|
There was a problem hiding this comment.
I think this merits a patch release after it is merged.
There was a problem hiding this comment.
Speaking of a patch. This may be a breaking change, because:
- I found that before, some constraints were dropped silently, and after the chance they produce a warning. I don't have an example in tests now, would you require one?
- Obviously, ordering for some cases has changed - I had to update tests to match it. Specifically, old versions of
tests.test_relative_ordering.test_dependency_loopandtests.test_relative_ordering.test_failed_tests_after_dependency_loopfail on the new code. - And of course there are customers who rely on the old, incomplete ordering 😆 😢
There was a problem hiding this comment.
Well, I still think of it as a bug fix. I know you are thinking of Hyrum's Law, but you just made cases possible that before have been handled (incorrectly) as a dependency loop. If somebody relied on that behavior to prevent some implied ordering, I certainly wouldn't bother about it...
There was a problem hiding this comment.
Also the warning was missing before, so it just improved the visibility of an incorrect marker.
… - _sort_by_topology() needs the dependencies before _apply_iterative() mutates it.
for more information, see https://pre-commit.ci
| ## Unreleased | ||
|
|
||
| ### Fixes | ||
| - relative order markers (`before`/`after`) now always take preference over |
There was a problem hiding this comment.
I wonder if this comment is necessary - this is the way it always worked, isn't it?
Or was it only about combination of relative/absolute on the same item?
There was a problem hiding this comment.
Yes, I actually wanted to ask in which cases it didn't work - I thought that you maybe had found such a case.
But yes, this should have been the way it work before (i.e., the comment can be removed).
There was a problem hiding this comment.
Removed that item. No, I didn't see any violations of this behavior.
…e way it always worked.
|
Comments addressed. Please lmk if you see anything else. |
We only use
beforeandafterconstraints edit: and afirst/last, and sometimes, with sparse transitive dependencies,pytest-orderwon't produce the order that we expect, silently ignoring one of the constraints.This is a set of changes that replaces the current algorithm with a topological sort, and adds a warning about impossible sets of constraints, for example:
@order(first) def test_foo(): pass; @order(before="test_foo") def test_bar(): pass.Created mostly by Claude.
This is a conversation starter. Please let me know if it needs to be squashed and split into smaller commits.