Repository: tox-dev/tox (Python)

Issue:
tox --help shows an error when run outside a directory with tox support files
[This is obviously minor, but figured I'd file it anyhow]

Running `tox --help` to just check usage options from no directory in particular (one that doesn't have a `tox.ini` etc.) shows an error:

```
⊙  tox --help                                                                                                                                                                                     julian@Air
ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
usage: tox [--version] [-h] [--help-ini] [-v] [-q] [--showconfig] [-l] [-a] [-c CONFIGFILE] [-e envlist] [--devenv ENVDIR] [--notest] [--sdistonly] [-p VAL] [-o] [--parallel--safe-build]
           [--installpkg PATH] [--develop] [-i URL] [--pre] [-r] [--result-json PATH] [--hashseed SEED] [--force-dep REQ] [--sitepackages] [--alwayscopy] [-s [val]] [--workdir PATH]
           [args [args ...]]

tox options
...
```

```
⊙  tox --version                                                                                                                                                                                  julian@Air
3.14.3 imported from /Users/julian/.local/share/virtualenvs/tox/site-packages/tox/__init__.py
```
tox --help-ini shows an error when run outside a directory with tox support files
similar to issue #1509  
Running tox --help-ini from no directory in particular (one that doesn't have a tox.ini etc.) shows an error:  
```
⊙  tox --help                                                                                                                                                                                     nkpro@Prime
ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
envdir          <path>   default: {toxworkdir}/{envname}
set venv directory -- be very careful when changing this as tox will remove this directory when recreating an environment
...
```


Discussion:

Patch:
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 21be9edf1..3449b12d1 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -65,6 +65,7 @@ Mikhail Kyshtymov
 Miro Hrončok
 Monty Taylor
 Morgan Fainberg
+Naveen S R
 Nick Douma
 Nick Prendergast
 Oliver Bestwalter
diff --git a/docs/changelog/1539.bugfix.rst b/docs/changelog/1539.bugfix.rst
new file mode 100644
index 000000000..51875f130
--- /dev/null
+++ b/docs/changelog/1539.bugfix.rst
@@ -0,0 +1,1 @@
+Fix ``tox -h`` and ``tox --hi`` shows an error when run outside a directory with tox support files by :user:`nkpro2000sr`.
diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py
index f6b348442..922e3bc51 100644
--- a/src/tox/config/__init__.py
+++ b/src/tox/config/__init__.py
@@ -270,6 +270,8 @@ def parseconfig(args, plugins=()):
         pm.hook.tox_configure(config=config)  # post process config object
         break
     else:
+        if option.help or option.helpini:
+            return config
         msg = "tox config file (either {}) not found"
         candidates = ", ".join(INFO.CONFIG_CANDIDATES)
         feedback(msg.format(candidates), sysexit=not (option.help or option.helpini))
diff --git a/tox.ini b/tox.ini
index 9b2c2b860..4e4f52b15 100644
--- a/tox.ini
+++ b/tox.ini
@@ -29,7 +29,8 @@ passenv =
     SSL_CERT_FILE
     PYTEST_*
     PIP_CACHE_DIR
-deps = pip >= 19.3.1
+deps =
+    pip >= 19.3.1
 extras = testing
 commands = pytest \
            --cov "{envsitepackagesdir}/tox" \
@@ -38,6 +39,11 @@ commands = pytest \
            -n={env:PYTEST_XDIST_PROC_NR:auto} \
            {posargs:.}
 
+[testenv:pypy]
+deps =
+    pip >= 19.3.1
+    psutil <= 5.6.7
+
 [testenv:docs]
 description = invoke sphinx-build to build the HTML docs
 basepython = python3.8


Test patch:
diff --git a/tests/unit/test_z_cmdline.py b/tests/unit/test_z_cmdline.py
index 71d2d796c..03246dcb1 100644
--- a/tests/unit/test_z_cmdline.py
+++ b/tests/unit/test_z_cmdline.py
@@ -84,13 +84,18 @@ def test_getvenv(self, initproj):
 def test_notoxini_help_still_works(initproj, cmd):
     initproj("example123-0.5", filedefs={"tests": {"test_hello.py": "def test_hello(): pass"}})
     result = cmd("-h")
-    msg = "ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found\n"
-    assert result.err == msg
     assert result.out.startswith("usage: ")
     assert any("--help" in l for l in result.outlines), result.outlines
     result.assert_success(is_run_test_env=False)
 
 
+def test_notoxini_noerror_in_help(initproj, cmd):
+    initproj("examplepro", filedefs={})
+    result = cmd("-h")
+    msg = "ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found\n"
+    assert result.err != msg
+
+
 def test_notoxini_help_ini_still_works(initproj, cmd):
     initproj("example123-0.5", filedefs={"tests": {"test_hello.py": "def test_hello(): pass"}})
     result = cmd("--help-ini")
@@ -98,6 +103,13 @@ def test_notoxini_help_ini_still_works(initproj, cmd):
     result.assert_success(is_run_test_env=False)
 
 
+def test_notoxini_noerror_in_help_ini(initproj, cmd):
+    initproj("examplepro", filedefs={})
+    result = cmd("--help-ini")
+    msg = "ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found\n"
+    assert result.err != msg
+
+
 def test_envdir_equals_toxini_errors_out(cmd, initproj):
     initproj(
         "interp123-0.7",