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

Test that depends on other tests in different file always skipped #48

Closed
tkedwards opened this issue Dec 6, 2020 · 4 comments
Closed

Comments

@tkedwards
Copy link

Hi,

I have a test that depends on 2 other tests:

# Test the GrowthQuality sub-class

import pytest
from SharepadDaten.calcvalues.calcs.GrowthQuality import *

@pytest.mark.parametrize("sharecode,expected", [
    ('RTN.L', Decimal(0.703).quantize(Decimal('.001'))),
    ('FL', Decimal(0.811).quantize(Decimal('.001'))),
    ('ALV.DE', Decimal(0.784).quantize(Decimal('.001'))),
])

@pytest.mark.dependency(
    depends=["tests_calculatedvalues/test_leaseLiabilities.py::test_leaseLiabilities", "tests_calculatedvalues/test_leaseAdjCapEmp.py::test_leaseAdjCapEmp"],
    scope='session'
)
def test_calcGrowthQuality(sharecode, expected, dbsession, tables):
    dbSession = dbsession
    SQLAlcBase = tables
    sharesDetailsClass = SQLAlcBase.classes['sharesDetails']   
    growthQuality = GrowthQuality(sharecode, dbSession, SQLAlcBase)
    assert growthQuality.value == expected

It depends on these 2 other tests, which are defined in separate .py files in the same directory:

@pytest.mark.dependency(name="test_leaseAdjCapEmp")
def test_leaseAdjCapEmp(sharecode, expected, dbsession, tables):
    dbSession = dbsession
    SQLAlcBase = tables
    sharesDetailsClass = SQLAlcBase.classes['sharesDetails']   
    leaseAdjCapEmpObj = leaseAdjCapEmp(sharecode, dbSession, SQLAlcBase)
    # IntermediateCalculatedValue tests should actually write to the DB, since other tests rely on these values being there
    leaseAdjCapEmpObj.outputValue() 
    assert leaseAdjCapEmpObj.values.equals(expected)
@pytest.mark.dependency(name="test_leaseLiabilities")
def test_leaseLiabilities(sharecode, expected, dbsession, tables):
    dbSession = dbsession
    SQLAlcBase = tables
    sharesDetailsClass = SQLAlcBase.classes['sharesDetails']   
    leaseLiab = leaseLiabilities(sharecode, dbSession, SQLAlcBase)
    # IntermediateCalculatedValue tests should actually write to the DB, since other tests rely on these values being there
    leaseLiab.outputValue() 
    assert leaseLiab.values.equals(expected)

When I run my tests I get:

SKIPPED [1] /usr/local/lib/python3.8/dist-packages/pytest_dependency.py:104: test_calcGrowthQuality[RTN.L-expected0] depends on tests_calculatedvalues/test_leaseAdjCapEmp.py::test_leaseAdjCapEmp
SKIPPED [1] /usr/local/lib/python3.8/dist-packages/pytest_dependency.py:104: test_calcGrowthQuality[FL-expected1] depends on tests_calculatedvalues/test_leaseAdjCapEmp.py::test_leaseAdjCapEmp
SKIPPED [1] /usr/local/lib/python3.8/dist-packages/pytest_dependency.py:104: test_calcGrowthQuality[ALV.DE-expected2] depends on tests_calculatedvalues/test_leaseAdjCapEmp.py::test_leaseAdjCapEmp

I've read https://pytest-dependency.readthedocs.io/en/stable/scope.html and I assume I've done something wrong with naming the tests, but I can't work out what. To me the name "tests_calculatedvalues/test_leaseLiabilities.py::test_leaseLiabilities" seems like it should be correct.

@mvanderlee
Copy link

I'm running into the same issue. pytest-dependency doesn't alter the execution order of files so, while it enforces the dependencies. PyTest still executes them in alphabetical order.

@tkedwards
Copy link
Author

Yeah I plan to use pytest-ordering module to get past this limitation. Just haven't had a chance yet to write it into my tests

@mrbean-bremen
Copy link

@tkedwards - you can you use pytest-order (a fork of pytest-ordering I created a few months ago) together with pytest-dependency. It has an option to order tests marked with dependency markers if needed. This way you won't lose the functionality from pytest-dependency (e.g. skipping skipped/failed tests) .

@tkedwards
Copy link
Author

Thanks, I did end up using pytest-order

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

3 participants