@@ -616,90 +616,72 @@ def test_with_specific_inifile(self, tmpdir):
616
616
assert rootdir == tmpdir
617
617
618
618
class TestOverrideIniArgs :
619
- """ test --override-ini """
620
619
@pytest .mark .parametrize ("name" , "setup.cfg tox.ini pytest.ini" .split ())
621
620
def test_override_ini_names (self , testdir , name ):
622
621
testdir .tmpdir .join (name ).write (py .std .textwrap .dedent ("""
623
622
[pytest]
624
- custom = 1.0
625
- """ ))
623
+ custom = 1.0""" ))
626
624
testdir .makeconftest ("""
627
625
def pytest_addoption(parser):
628
- parser.addini("custom", "")
629
- """ )
626
+ parser.addini("custom", "")""" )
630
627
testdir .makepyfile ("""
631
628
def test_pass(pytestconfig):
632
629
ini_val = pytestconfig.getini("custom")
633
- print('\\ ncustom_option:%s\\ n' % ini_val)
634
- """ )
630
+ print('\\ ncustom_option:%s\\ n' % ini_val)""" )
635
631
636
632
result = testdir .runpytest ("--override-ini" , "custom=2.0" , "-s" )
637
633
assert result .ret == 0
638
- result .stdout .fnmatch_lines ([
639
- "custom_option:2.0"
640
- ])
634
+ result .stdout .fnmatch_lines (["custom_option:2.0" ])
641
635
642
636
result = testdir .runpytest ("--override-ini" , "custom=2.0" ,
643
637
"--override-ini=custom=3.0" , "-s" )
644
638
assert result .ret == 0
645
- result .stdout .fnmatch_lines ([
646
- "custom_option:3.0"
647
- ])
639
+ result .stdout .fnmatch_lines (["custom_option:3.0" ])
648
640
649
641
650
642
def test_override_ini_pathlist (self , testdir ):
651
643
testdir .makeconftest ("""
652
- def pytest_addoption(parser):
653
- parser.addini("paths", "my new ini value", type="pathlist")
654
- """ )
644
+ def pytest_addoption(parser):
645
+ parser.addini("paths", "my new ini value", type="pathlist")""" )
655
646
testdir .makeini ("""
656
- [pytest]
657
- paths=blah.py
658
- """ )
647
+ [pytest]
648
+ paths=blah.py""" )
659
649
testdir .makepyfile ("""
660
- import py.path
661
- def test_pathlist(pytestconfig):
662
- config_paths = pytestconfig.getini("paths")
663
- print(config_paths)
664
- for cpf in config_paths:
665
- print('\\ nuser_path:%s' % cpf.basename)
666
- """ )
667
- result = testdir .runpytest ("--override-ini" , 'paths=foo/bar1.py foo/bar2.py' , "-s" )
668
- result .stdout .fnmatch_lines ([
669
- "user_path:bar1.py" ,
670
- "user_path:bar2.py"
671
- ])
650
+ import py.path
651
+ def test_pathlist(pytestconfig):
652
+ config_paths = pytestconfig.getini("paths")
653
+ print(config_paths)
654
+ for cpf in config_paths:
655
+ print('\\ nuser_path:%s' % cpf.basename)""" )
656
+ result = testdir .runpytest ("--override-ini" ,
657
+ 'paths=foo/bar1.py foo/bar2.py' , "-s" )
658
+ result .stdout .fnmatch_lines (["user_path:bar1.py" ,
659
+ "user_path:bar2.py" ])
672
660
673
661
def test_override_multiple_and_default (self , testdir ):
674
662
testdir .makeconftest ("""
675
- def pytest_addoption(parser):
676
- parser.addini("custom_option_1", "", default="o1")
677
- parser.addini("custom_option_2", "", default="o2")
678
- parser.addini("custom_option_3", "", default=False, type="bool")
679
- parser.addini("custom_option_4", "", default=True, type="bool")
680
-
681
- """ )
663
+ def pytest_addoption(parser):
664
+ addini = parser.addini
665
+ addini("custom_option_1", "", default="o1")
666
+ addini("custom_option_2", "", default="o2")
667
+ addini("custom_option_3", "", default=False, type="bool")
668
+ addini("custom_option_4", "", default=True, type="bool")""" )
682
669
testdir .makeini ("""
683
- [pytest]
684
- custom_option_1=custom_option_1
685
- custom_option_2=custom_option_2
686
- """ )
670
+ [pytest]
671
+ custom_option_1=custom_option_1
672
+ custom_option_2=custom_option_2""" )
687
673
testdir .makepyfile ("""
688
- def test_multiple_options(pytestconfig):
689
- prefix="custom_option"
690
- for x in range(1,5):
691
- ini_value=pytestconfig.getini("%s_%d" % (prefix, x))
692
- print('\\ nini%d:%s' % (x, ini_value))
693
- """ )
694
- result = testdir .runpytest ("--override-ini" ,
695
- 'custom_option_1=fulldir=/tmp/user1' ,
696
- 'custom_option_2=url=/tmp/user2?a=b&d=e' ,
697
- "-o" , 'custom_option_3=True' ,
698
- "-o" , 'custom_option_4=no' ,
699
- "-s" )
700
- result .stdout .fnmatch_lines ([
701
- "ini1:fulldir=/tmp/user1" ,
702
- "ini2:url=/tmp/user2?a=b&d=e" ,
703
- "ini3:True" ,
704
- "ini4:False"
705
- ])
674
+ def test_multiple_options(pytestconfig):
675
+ prefix = "custom_option"
676
+ for x in range(1, 5):
677
+ ini_value=pytestconfig.getini("%s_%d" % (prefix, x))
678
+ print('\\ nini%d:%s' % (x, ini_value))""" )
679
+ result = testdir .runpytest (
680
+ "--override-ini" , 'custom_option_1=fulldir=/tmp/user1' ,
681
+ 'custom_option_2=url=/tmp/user2?a=b&d=e' ,
682
+ "-o" , 'custom_option_3=True' ,
683
+ "-o" , 'custom_option_4=no' , "-s" )
684
+ result .stdout .fnmatch_lines (["ini1:fulldir=/tmp/user1" ,
685
+ "ini2:url=/tmp/user2?a=b&d=e" ,
686
+ "ini3:True" ,
687
+ "ini4:False" ])
0 commit comments