File tree Expand file tree Collapse file tree 5 files changed +47
-0
lines changed
Expand file tree Collapse file tree 5 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ The ``tox-current-env`` plugin adds these options:
3636 Use ``- `` for ``FILE `` to print to standard output.
3737 This option only exists with tox 4 and requires at least tox 4.22.
3838
39+ ``tox --assert-config ``
40+ Starting with tox 4, tox does not terminate when no configuration is found.
41+ This option makes tox fail (raise an exception) when no configuration exists.
42+ On tox 3, this option does nothing, but can be used.
43+ This option can be combined with others.
44+
3945It is possible to use the three printing options together, as long as the ``FILE `` is different.
4046
4147Invoking ``tox `` without any of the above options should behave as regular ``tox `` invocation without this plugin.
Original file line number Diff line number Diff line change @@ -48,6 +48,12 @@ def tox_addoption(parser):
4848 help = "Don't run tests, only print the names of the required extras to the given file "
4949 + "(use `-` for stdout)" ,
5050 )
51+ parser .add_argument (
52+ "--assert-config" ,
53+ action = "store_true" ,
54+ default = False ,
55+ help = "Fail if no tox configuration is found (default on tox 3, does nothing)" ,
56+ )
5157
5258
5359def _plugin_active (option ):
Original file line number Diff line number Diff line change @@ -66,12 +66,21 @@ def tox_add_option(parser):
6666 help = "Don't run tests, only print the names of the required dependency-groups to the given file "
6767 + "(use `-` for stdout)" ,
6868 )
69+ parser .add_argument (
70+ "--assert-config" ,
71+ action = "store_true" ,
72+ default = False ,
73+ help = "Fail if no tox configuration is found" ,
74+ )
6975
7076
7177@impl
7278def tox_add_core_config (core_conf , state ):
7379 opt = state .conf .options
7480
81+ if opt .assert_config and not state .conf .src_path .exists ():
82+ raise LookupError ("tox configuration not found." )
83+
7584 if opt .current_env or opt .print_deps_to or opt .print_extras_to or opt .print_dependency_groups_to :
7685 # We do not want to install the main package.
7786 # no_package is the same as skipsdist.
Original file line number Diff line number Diff line change @@ -580,3 +580,16 @@ def test_passenv(projdir, passenv):
580580 assert result .returncode == 0
581581 assert "\n assertme\n " in result .stdout
582582 assert "\n None\n " not in result .stdout
583+
584+
585+ def test_assert_config_option_with_config (projdir ):
586+ result = tox ("-l" , "--assert-config" , check = False )
587+ assert result .returncode == 0
588+
589+
590+ def test_assert_config_option_without_config (projdir ):
591+ (projdir / "tox.ini" ).unlink ()
592+ result = tox ("-l" , "--assert-config" , check = False )
593+ assert result .returncode > 0
594+ assert "config" in result .stderr
595+ assert "not found" in result .stderr
Original file line number Diff line number Diff line change @@ -591,3 +591,16 @@ def test_report_installed(projdir):
591591 assert result .returncode == 0
592592 assert "tox==" in result .stdout
593593 assert "pytest==" in result .stdout
594+
595+
596+ def test_assert_config_option_with_config (projdir ):
597+ result = tox ("-l" , "--assert-config" , check = False )
598+ assert result .returncode == 0
599+
600+
601+ def test_assert_config_option_without_config (projdir ):
602+ (projdir / "tox.ini" ).unlink ()
603+ result = tox ("-l" , "--assert-config" , check = False )
604+ assert result .returncode > 0
605+ assert "config" in result .stderr
606+ assert "not found" in result .stderr
You can’t perform that action at this time.
0 commit comments