I'm working on a functional test suite using pytest with pytest-dependency. I 99% love these tools, but I can't figure out how to have a test in one file depend on a test in another file. Ideally, I'd like to have zero changes required to the dependee, and only change things in the depender. I'd like tests to be able to depend on test_one both like this:
# contents of test_one.py
@pytest.mark.dependency()
def test_one():
# do stuff
@pytest.mark.dependency(depends=["test_one"])
def test_point_one():
# do stuff
And like this:
# contents of test_two.py
@pytest.mark.dependency(depends=["test_one"])
def test_two():
# do stuff
When I run pytest test_one.py
it correctly orders things (and skips test_point_one
if test_one
fails), but when I run pytest test_two.py
, it skips test_two
.
I've tried adding import test_one
to test_two.py to no avail, and verified that the import is actually importing properly - it's not just getting passed over by pytest going "Oh hey, I've finished collecting tests, and there's nothing that I can't skip! Hooray for laziness!"
I know I could technically put test_two()
in test_one.py
and it would work, but I don't want to just dump every test in a single file (which is what this would ultimately devolve into). I'm trying to keep stuff tidy by putting everything on the right shelf, not just shoving it all into the closet.
Also, I realize the possibility of creating circular dependencies would exist if this is something I can do. I'm okay with this. If I shot myself in the foot like that, let's be honest, I'd deserve it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…