@@ -566,3 +566,107 @@ def test_class_fail(code, tmpdir):
566566 # If we don't use --mpl option, the test should succeed
567567 code = call_pytest ([test_file ])
568568 assert code == 0
569+
570+
571+ @pytest .mark .parametrize ("runpytest_args" , [(), ("--mpl" ,)])
572+ def test_user_fail (pytester , runpytest_args ):
573+ pytester .makepyfile (
574+ """
575+ import pytest
576+ @pytest.mark.mpl_image_compare
577+ def test_fail():
578+ pytest.fail("Manually failed by user.")
579+ """
580+ )
581+ result = pytester .runpytest (* runpytest_args )
582+ result .assert_outcomes (failed = 1 )
583+ result .stdout .fnmatch_lines ("FAILED*Manually failed by user.*" )
584+
585+
586+ @pytest .mark .parametrize ("runpytest_args" , [(), ("--mpl" ,)])
587+ def test_user_skip (pytester , runpytest_args ):
588+ pytester .makepyfile (
589+ """
590+ import pytest
591+ @pytest.mark.mpl_image_compare
592+ def test_skip():
593+ pytest.skip("Manually skipped by user.")
594+ """
595+ )
596+ result = pytester .runpytest (* runpytest_args )
597+ result .assert_outcomes (skipped = 1 )
598+
599+
600+ @pytest .mark .parametrize ("runpytest_args" , [(), ("--mpl" ,)])
601+ def test_user_importorskip (pytester , runpytest_args ):
602+ pytester .makepyfile (
603+ """
604+ import pytest
605+ @pytest.mark.mpl_image_compare
606+ def test_importorskip():
607+ pytest.importorskip("nonexistantmodule")
608+ """
609+ )
610+ result = pytester .runpytest (* runpytest_args )
611+ result .assert_outcomes (skipped = 1 )
612+
613+
614+ @pytest .mark .parametrize ("runpytest_args" , [(), ("--mpl" ,)])
615+ def test_user_xfail (pytester , runpytest_args ):
616+ pytester .makepyfile (
617+ """
618+ import pytest
619+ @pytest.mark.mpl_image_compare
620+ def test_xfail():
621+ pytest.xfail()
622+ """
623+ )
624+ result = pytester .runpytest (* runpytest_args )
625+ result .assert_outcomes (xfailed = 1 )
626+
627+
628+ @pytest .mark .parametrize ("runpytest_args" , [(), ("--mpl" ,)])
629+ def test_user_exit_success (pytester , runpytest_args ):
630+ pytester .makepyfile (
631+ """
632+ import pytest
633+ @pytest.mark.mpl_image_compare
634+ def test_exit_success():
635+ pytest.exit("Manually exited by user.", returncode=0)
636+ """
637+ )
638+ result = pytester .runpytest (* runpytest_args )
639+ result .assert_outcomes ()
640+ assert result .ret == 0
641+ result .stdout .fnmatch_lines ("*Exit*Manually exited by user.*" )
642+
643+
644+ @pytest .mark .parametrize ("runpytest_args" , [(), ("--mpl" ,)])
645+ def test_user_exit_failure (pytester , runpytest_args ):
646+ pytester .makepyfile (
647+ """
648+ import pytest
649+ @pytest.mark.mpl_image_compare
650+ def test_exit_fail():
651+ pytest.exit("Manually exited by user.", returncode=1)
652+ """
653+ )
654+ result = pytester .runpytest (* runpytest_args )
655+ result .assert_outcomes ()
656+ assert result .ret == 1
657+ result .stdout .fnmatch_lines ("*Exit*Manually exited by user.*" )
658+
659+
660+ @pytest .mark .parametrize ("runpytest_args" , [(), ("--mpl" ,)])
661+ def test_user_function_raises (pytester , runpytest_args ):
662+ pytester .makepyfile (
663+ """
664+ import pytest
665+ @pytest.mark.mpl_image_compare
666+ def test_raises():
667+ raise ValueError("User code raised an exception.")
668+ """
669+ )
670+ result = pytester .runpytest (* runpytest_args )
671+ result .assert_outcomes (failed = 1 )
672+ result .stdout .fnmatch_lines ("FAILED*ValueError*User code*" )
0 commit comments