Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect dependencies #56

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open

Conversation

ftesser
Copy link

@ftesser ftesser commented Oct 6, 2021

Hello @RKrahl, the purpose of this PR is to add the possibility of automatically collect dependent tests.

Is similar to what proposed in #37, but differs from these points:

  • the behaviour is automatically spread on all tests (no need to add the mark parameter collect=True)
  • the behaviour is enable/disable by a configuration that can be set in the ini file;
  • the searching of dependent tests is recursive;

This configuration option default is set to false, so pytest-dependency does not change its default beauvoir.

Just to explain my motivation for this PR, my use case is the following:

I use PyCharm IDE, running a single test is made by clicking on the green triangle on the left of the function test definition (see image below):

image

Using this new feature the result for a single click is the execution of that test and all the dependent tests. I think that most IDEs have similar way to run a single test, and so this option can have its benefit also there.

@dvarrazzo
Copy link

Looks like the author of this MR and me are going after the same idea.

See this comment for my explanation about why this feature would be really useful for a pytest dependency-tracking extension.

@dvarrazzo
Copy link

Hello! Any chance for this feature to be developed? Can we provide some help to release this useful feature? Thank you 🙂

@quanthom
Copy link

quanthom commented Nov 2, 2022

This feature is very useful, what is blocking the CI failures to be fixed and the branch merged?

to fix  "WARNING: Built wheel for pytest-dependency is invalid: Metadata 1.2 mandates PEP 440 version, but 'UNKNOWN' is not
@marcinwrochna
Copy link

I believe pytest_collection_modifyitems should me marked with @pytest.hookimpl(trylast=True), otherwise it may happen before items are deselected with the default built-in pytest key/mark selections (it happened to me).

@ydirson
Copy link

ydirson commented May 24, 2024

This code does not take into account tests in a class, when referred to as follows:

class Tests:
    @pytest.mark.dependency()
    def test_b(self):
        pass

    @pytest.mark.dependency(depends=["Tests::test_b"])
    def test_d(self):
        pass

The following Q&D patch takes care of that case, but I'm not sure it would handle all situations:

                     depend_parent = Module.from_parent(item.parent, fspath=depend_path)
                     depend_nodeid = depend
                 else:
-                    depend_func = depend
+                    if "::" in depend:
+                        depend_func = depend.split("::")[-1]
+                    else:
+                        depend_func = depend
                     depend_parent = item.parent
                     depend_nodeid = '{}::{}'.format(depend_parent.nodeid, depend_func)
                     # assert depend_nodeid == depend_nodeid2

Edit: that uses the current item's parent to create the dependency item, which will only work if they are defined in the same class, e.g. this is not covered:

@pytest.mark.dependency()
class Tests:
    def test_b(self):
        pass

class TestOtherTests:
    @pytest.mark.dependency(depends=["Tests::test_b"])
    def test_d(self):
        pass

Another limitation is the item does not seem to include fixture information, and when pytest wants to run that item we added, we get a required positional argument TypeError.

pytest_collection_modifyitems is indeed documented as "May filter or re-order the items in-place", the lack of "add" here is likely a hint that this is not the right approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants