Skip to content

[Label] Allow specifying full directories/files as order targets #51

Open

Description

@Joacchim

Hello,

I've been fiddling with pytest-order for a personal project.
I wanted to order tests based on files and/or subdirectories, and I believe that it is not feasible at the moment with pytest-order.

Looking a bit into it, I've observed (correct me if I'm misunderstanding something) that the labels should mostly hint at discrete tests, and never at a bunch of other tests (all tests from a directory, file).

Is it possible to provide a feature such as full directory/file-based ordering ? I felt it should be, since the module already supports specifying multiple tests as before/after ordering labels.

I believe it may relate to #50, as the subject matter might end up cross paths.

Note: I've fiddled a bit with the code to obtain something that looks like it might work, but I might also be unknowingly passing-by some major problematics in doing so. If you're interested nonetheless, I can provide an initial PR to serve as a discussion basis, and hopefully contribute to obtaining said feature.

Cheers !

Activity

  1. ltrujello commented on Mar 1, 2023

    @ltrujello

    @Joacchim would you mind sharing your stab at implementing this feature? I am also interested.

    In my opinion, this feature would be much cooler than what pytest-order currently offers.

    It is actually much more useful to specify the order your test files run rather than the individual tests. E.g., most projects that are complicated enough to have tests usually have hundreds of tests. Are the developers really going to label the order of every singe test function? Probably not, that's just too complicated. It'd be much more useful to order the files that the hundreds of tests are split up between.

    For context my use case: I would like my very slow integration test file to run last. Because of alphabetical ordering, they run first. Thus, every time I make a new, fast test, I have to wait for my slow integration tests to run first. I still want that test to run of course, but it'd be more useful for my newly added fast test to fail first (failing fast helps you iterate faster).

  2. mrbean-bremen commented on Mar 1, 2023

    @mrbean-bremen
    Member

    @ltrujello - have a look at this question for your problem. I know it's not ideal, but at least it will work.
    For the work @Joacchim has started - see his PR #52. If you want to have a shot, you can take that as a base. It is unlikely that I will get to it myself very soon, as I am busy with other projects at the moment.

  3. jenstroeger commented on May 2, 2025

    @jenstroeger

    I’d like to see this feature too: in my case I’d like to test an API and first test the signup endpoint (i.e. run the test_signup.py module); next test the login endpoint (i.e. run the test_login.py module) because it requires signup to work; next test the profile endpoint (i.e. run the test_profile.py module) because it requires login to work; and so forth…

  4. mrbean-bremen commented on May 2, 2025

    @mrbean-bremen
    Member

    @jenstroeger: have a look at #124. If this is all you want to do, you can add

    pytestmark = pytest.mark.order(0)

    in test_signup.py,

    pytestmark = pytest.mark.order(1)

    in test_login.py and so on.
    Thinking about this, you actually may not have to use --order-group-scope=module as mentioned in the discussion issue, though I'm not quite sure about this, and it wouldn't hurt.

  5. jenstroeger commented on May 2, 2025

    @jenstroeger

    @mrbean-bremen I think you’re right: the pytestmark global worked as you suggested, even without the cmd line arg 👍🏼

  6. mrbean-bremen commented on May 2, 2025

    @mrbean-bremen
    Member

    I'll probably add this to the documentation - this is a valid use case that is not obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions