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

Register package-scoped dependencies with default name relative to the node path #46

Open
LECbg opened this issue Oct 7, 2020 · 1 comment

Comments

@LECbg
Copy link

LECbg commented Oct 7, 2020

I find it rather impractical for large test suites to name both session and package scoped dependencies with the full node id. Wouldn't it be more logical to remove the path of that package from the name? From what I can understand, it is even redundant to name that dependency (in a package scope) including the full path.

I'll try to give an example, for the sake of clarity.

Given a project structure somewhat like:

/project
    /app1
        /tests
            test_file1.py
            test_file2.py
    /app2
        /tests
            test_file1.py
            test_file2.py

With tests:

# app1/tests/test_file1.py

@pytest.mark.dependency()
def test_a():
    pass

and

# app1/tests/test_file2.py

@pytest.mark.dependency(depends=['app1/tests/test_file1.py::test_a'], scope='package')
def test_b():
    pass

It would seem more logical to me to be able to do this like:

# app1/tests/test_file2.py

@pytest.mark.dependency(depends=['test_file1.py::test_a'], scope='package')
def test_b():
    pass

Which in turn wouldn't cause any conflict with the following (if I'm not wrong):

# app2/tests/test_file1.py

@pytest.mark.dependency()
def test_a():
    pass
# app2/tests/test_file2.py

@pytest.mark.dependency(depends=['test_file1.py::test_a'], scope='package')
def test_b():
    pass

I hope I have explained myself as clearly as possible and would appreciate any feedback.
Thanks in advance.

@madzohan
Copy link

madzohan commented Nov 20, 2020

Feels like it already works but seems not documented here

Note that the references in session scope must use the full node id of the dependencies. This node id is composed of the module path, the name of the test class if applicable, and the name of the test, separated by a double colon “::”, see Section Names for details. References in module scope on the other hand must omit the module path in the node id, because that is implied by the scope.

pytest-dependency = "==0.5.1" if you look at code here pytest_dependency.DependencyManager.checkDepend you can notice that - manager checks by registered names in session scope which succeeded

For example I have project like this:


project
    api
        __init__.py
        tests
            __init__.py
            test_a.py
            test_b.py
    api2
        __init__.py
        tests
            __init__.py
            test_a.py

in api/test_a.py:

@pytest.mark.parametrize("response_is_valid, product_q_count, review_q_count", [
    pytest.param(False, 0, 0, marks=pytest.mark.dependency(name="cli_parse_cmd_invalid")),
    pytest.param(True, 2, 2, marks=pytest.mark.dependency(name="cli_parse_cmd_valid"))])
def test_cli_parse_cmd(response_is_valid, product_q_count, review_q_count)
    pass

and in api/test_b.py:

@pytest.mark.dependency(depends=["cli_parse_cmd_valid"], scope="session")
def test_product_get(client, request):
    pass

and in api2/test_a.py

@pytest.mark.dependency(depends=["cli_parse_cmd_valid"], scope="session")
def test_something(request):
    pass

tests executed and passed 😄

api/tests/test_a.py::test_cli_parse_cmd[True-2-2] PASSED           [ 75%]
api2/tests/test_b.py::test_product_get PASSED                      [ 83%]
api2/tests/test_a.py::test_product_get PASSED                      [ 100%]

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

No branches or pull requests

2 participants