pytest-order icon indicating copy to clipboard operation
pytest-order copied to clipboard

[Labels] Cannot specify Full-Class ordering from another file

Open Joacchim opened this issue 3 years ago • 4 comments

Hello,

In order to order the tests of a personal project, I've attempted to order tests on the basis of files (or the classes within it), in order to keep the ordering specification short and concise. Note that I've also encountered issues ordering tests in a similar way to the documentation, by specifying a class name as the label.

Alas, it seems that is does not work this way (or is not intended to ?), as I only receive a Warning telling me that the mark is ignored, in light of the failure to match a node_id with the provided label.

Looking a bit into the code, I noticed that the code path handling Class-based dependencies has the constraint of containing exactly two :: strings, meaning that it must probably be a test-name from within a specific test-class.

I believe that it would be quite practical to be able to order tests relatively to test classes, not only from the same file, but also from other test files, as the documentation does not hint at the impossibility to do so.

Thank you for maintaining this piece of code, in hope that my feedback here may help the project and other users !

Joacchim avatar Aug 05 '21 22:08 Joacchim

Just to be clear (I may nor understand the issue correctly):

  • you don't want to order tests inside a test module, but only the test modules themselves
  • you are using --order-scope=module
  • you don't want to put a full test name in the marker, but only the module path as a more convenient way

Is that correct, or do you mean something else?

mrbean-bremen avatar Aug 06 '21 05:08 mrbean-bremen

  1. Actually if I could do both, that'd be ideal (sorry, I'm greedy, I know :D)
  2. I haven't been using the --order-scope option, as I wasn't sure it would fit my need, and didn't look too much into it yet
  3. Yes, the point is to keep the names as short as reasonably possible (as opposed to pytest-dependency which I've used and is particularly verbose on that point, but still allows depending on whole classes from another module)

Joacchim avatar Aug 06 '21 07:08 Joacchim

Ok, --order-scope=module means that tests in different modules are not mixed. You can sort tests inside a module, but if you order against tests in other modules, that would just mean that the test modules would be sorted accordingly. So, if you order against the test in another module without an --order-scope option (say using before), that single test would be moved before the test in the other module. With that option, all tests in the module would be excuted before the tests in the other module - as far as I understand, this is what you want.

I understand that you want to use just the module name as marker to achieve the same, but that could be a bit tricky. I'm not sure that I could get this working without breaking anything else without major refactorings. You wrote in the other issue that you already adapted the code and could make a PR - I would be interested in that!

mrbean-bremen avatar Aug 06 '21 08:08 mrbean-bremen

I guess I should try again with --order-scope=module then, and see if it works as I wanted it to.

About my patch, alright, I'll open a Draft PR to discuss this tonight (it may not suit your intended design though, we'll see :D)

Joacchim avatar Aug 06 '21 08:08 Joacchim