question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reorder test execution based on dependencies?

See original GitHub issue

Is there any intent to reorder test execution according to dependencies? The current behavior I observe is that if I have two tests, where the first depends on the second, the first is just skipped. It would be preferable to reorder them so that they can both execute, rather than relying on source code order.

import pytest


@pytest.mark.dependency(depends=["test_parent"])
def test_child():
    pass


@pytest.mark.dependency
def test_parent():
    pass
$ pytest
==== test session starts ====
platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /tests, inifile:
plugins: dependency-0.3.2
collected 2 items

test_file.py::test_child SKIPPED
test_file.py::test_parent PASSED

==== 2 passed, 1 skipped in 0.01 seconds ====

NOTE: https://github.com/ftobia/pytest-ordering does some of this, but requires explicit ordering. I’d rather just define the dependencies and let the system figure it out.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
ftessercommented, Apr 15, 2021

Hi all, I suggest to all the people interesting in this issue, to have a look to pytest-depends (https://pypi.org/project/pytest-depends/; https://gitlab.com/MaienM/pytest-depends).

1reaction
lukjakcommented, Jan 9, 2022

Using both plugins forces to define order twice (implicitly with pytest-dependency and explicitly with pytest-order), while pytest-dependency already determines the execution order. Plus, it’s easy to create conflicting orders:

@pytest.mark.depency(name="test1")
@pytest.mark.order(2)
def test_test1():
   pass

@pytest.mark.depency(depends="test1")
@pytest.mark.order(1)
def test_test2():
   pass

Pytest-dependency already defines execution order, but does not enforce it in any way. It should be essential part of it.

Looking at a car, all a driver does is turning a steering wheel and pushing pedals in order to travel. But there is a lot more required in addition to supporting the steering wheel and the pedals in order to make the driver travel.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependencies and ordering of tests - Testim overview
Although we definitely prefer to endorse the best practice of isolated tests, we did leave a way to organize the execution order.
Read more >
Determine the order of Tests when tests have dependencies ...
Let's consider each test case as Vertex and dependency between two tests as Edge between two vertices. So, for example, B depends on...
Read more >
Test case execution order in pytest - python - Stack Overflow
Mark test dependency as fixture and pass it as an argument to dependent one. Save this answer.
Read more >
The Order of Tests in JUnit - Baeldung
Learn how to run JUnit tests in a custom order. ... MethodName to sort test methods based on their names and their formal...
Read more >
What are TestNG Dependent Tests and How to ... - Tools QA
Since the group and the annotation is the same, TestNG will run the methods in the alphabetical order · TestNG lets you create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found