Skip to content

Commit 436a409

Browse files
committed
Add tests for the depends() function.
1 parent 499ab53 commit 436a409

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

tests/test_03_scope.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,119 @@ def test_l(self):
482482
test_scope_named.py::TestClass::test_k PASSED
483483
test_scope_named.py::TestClass::test_l SKIPPED
484484
""")
485+
486+
@pytest.mark.xfail(reason="scope arg to depends() not yet implemented")
487+
def test_scope_dependsfunc(ctestdir):
488+
"""Test the scope argument to the depends() function.
489+
"""
490+
ctestdir.makepyfile(test_scope_dependsfunc_01="""
491+
import pytest
492+
493+
@pytest.mark.dependency()
494+
def test_a():
495+
pass
496+
497+
@pytest.mark.dependency()
498+
def test_b():
499+
assert False
500+
501+
@pytest.mark.dependency(depends=["test_a"])
502+
def test_c():
503+
pass
504+
505+
class TestClass(object):
506+
507+
@pytest.mark.dependency()
508+
def test_b(self):
509+
pass
510+
""", test_scope_dependsfunc_02="""
511+
import pytest
512+
from pytest_dependency import depends
513+
514+
@pytest.mark.dependency()
515+
def test_a():
516+
assert False
517+
518+
@pytest.mark.dependency()
519+
def test_b():
520+
pass
521+
522+
@pytest.mark.dependency()
523+
def test_e(request):
524+
depends(request,
525+
["test_scope_dependsfunc_01.py::test_a",
526+
"test_scope_dependsfunc_01.py::test_c"],
527+
scope='session')
528+
pass
529+
530+
@pytest.mark.dependency()
531+
def test_f(request):
532+
depends(request,
533+
["test_scope_dependsfunc_01.py::test_b"],
534+
scope='session')
535+
pass
536+
537+
@pytest.mark.dependency()
538+
def test_g(request):
539+
depends(request,
540+
["test_scope_dependsfunc_02.py::test_e"],
541+
scope='session')
542+
pass
543+
544+
@pytest.mark.dependency()
545+
def test_h(request):
546+
depends(request,
547+
["test_scope_dependsfunc_01.py::TestClass::test_b"],
548+
scope='session')
549+
pass
550+
551+
@pytest.mark.dependency()
552+
def test_i(request):
553+
depends(request, ["test_a"], scope='module')
554+
pass
555+
556+
@pytest.mark.dependency()
557+
def test_j(request):
558+
depends(request, ["test_b"], scope='module')
559+
pass
560+
561+
class TestClass(object):
562+
563+
@pytest.mark.dependency()
564+
def test_a(self):
565+
pass
566+
567+
@pytest.mark.dependency()
568+
def test_b(self):
569+
assert False
570+
571+
@pytest.mark.dependency()
572+
def test_c(self, request):
573+
depends(request, ["test_a"], scope='class')
574+
pass
575+
576+
@pytest.mark.dependency()
577+
def test_d(self, request):
578+
depends(request, ["test_b"], scope='class')
579+
pass
580+
""")
581+
result = ctestdir.runpytest("--verbose")
582+
result.assert_outcomes(passed=10, skipped=3, failed=3)
583+
result.stdout.fnmatch_lines("""
584+
test_scope_dependsfunc_01.py::test_a PASSED
585+
test_scope_dependsfunc_01.py::test_b FAILED
586+
test_scope_dependsfunc_01.py::test_c PASSED
587+
test_scope_dependsfunc_01.py::TestClass::test_b PASSED
588+
test_scope_dependsfunc_02.py::test_a FAILED
589+
test_scope_dependsfunc_02.py::test_b PASSED
590+
test_scope_dependsfunc_02.py::test_e PASSED
591+
test_scope_dependsfunc_02.py::test_f SKIPPED
592+
test_scope_dependsfunc_02.py::test_g PASSED
593+
test_scope_dependsfunc_02.py::test_h PASSED
594+
test_scope_dependsfunc_02.py::test_i SKIPPED
595+
test_scope_dependsfunc_02.py::test_j PASSED
596+
test_scope_dependsfunc_02.py::TestClass::test_a PASSED
597+
test_scope_dependsfunc_02.py::TestClass::test_b FAILED
598+
test_scope_dependsfunc_02.py::TestClass::test_c PASSED
599+
test_scope_dependsfunc_02.py::TestClass::test_d SKIPPED
600+
""")

0 commit comments

Comments
 (0)