Repository: tox-dev/tox

Issue:
tox 3.0.0rc1 breaks ``devpi test``
From https://github.com/tox-dev/tox/issues/728#issuecomment-361198048

The change of ``cmdline`` in f85b827c54de0f2531f69fc0c4883c8f4f3c8ecc broke ``devpi test``.

It's easy to fix on the devpi side, but I'm not sure if it will also break detox. I wasn't able to get detox tests running when I tried.

Maybe it would be better to revert ``cmdline`` back to ``test.session.main`` and change the entry point to tox.session.run_main instead.

cc @gaborbernat @obestwalter 

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/tox-dev/tox/pull/756?src=pr&el=h1) Report
> Merging [#756](https://codecov.io/gh/tox-dev/tox/pull/756?src=pr&el=desc) into [master](https://codecov.io/gh/tox-dev/tox/commit/1d6ca4b5c488c9c8ba10d25cb79ca89c254cd786?src=pr&el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/tox-dev/tox/pull/756/graphs/tree.svg?src=pr&token=DYodAwDCZ5&width=650&height=150)](https://codecov.io/gh/tox-dev/tox/pull/756?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #756      +/-   ##
==========================================
- Coverage   94.88%   94.84%   -0.05%     
==========================================
  Files          11       11              
  Lines        2386     2386              
==========================================
- Hits         2264     2263       -1     
- Misses        122      123       +1
```


| [Impacted Files](https://codecov.io/gh/tox-dev/tox/pull/756?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tox/\_\_init\_\_.py](https://codecov.io/gh/tox-dev/tox/pull/756/diff?src=pr&el=tree#diff-dG94L19faW5pdF9fLnB5) | `93.33% <100%> (ø)` | :arrow_up: |
| [tox/\_pytestplugin.py](https://codecov.io/gh/tox-dev/tox/pull/756/diff?src=pr&el=tree#diff-dG94L19weXRlc3RwbHVnaW4ucHk=) | `96% <0%> (-0.45%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tox-dev/tox/pull/756?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tox-dev/tox/pull/756?src=pr&el=footer). Last update [1d6ca4b...f758fb9](https://codecov.io/gh/tox-dev/tox/pull/756?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/changelog/755.bugfix.rst b/changelog/755.bugfix.rst
new file mode 100644
index 00000000..cbd625a6
--- /dev/null
+++ b/changelog/755.bugfix.rst
@@ -0,0 +1,1 @@
+fix #755 by reverting the ``cmdline`` import to the old location and changing the entry point instead - by @fschulze
diff --git a/setup.py b/setup.py
index 4d91d9f6..6fc8eb6a 100644
--- a/setup.py
+++ b/setup.py
@@ -43,7 +43,7 @@ def main():
         author='holger krekel',
         author_email='holger@merlinux.eu',
         packages=['tox'],
-        entry_points={'console_scripts': ['tox=tox:cmdline',
+        entry_points={'console_scripts': ['tox=tox.session:run_main',
                                           'tox-quickstart=tox._quickstart:main']},
         python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
         setup_requires=['setuptools_scm'],
diff --git a/tox/__init__.py b/tox/__init__.py
index b7a16315..ba64b356 100644
--- a/tox/__init__.py
+++ b/tox/__init__.py
@@ -52,6 +52,6 @@ class exception:
             super(exception.MinVersionError, self).__init__(message)
 
 
-from .session import run_main as cmdline  # noqa
+from .session import main as cmdline  # noqa
 
 __all__ = ('hookspec', 'hookimpl', 'cmdline', 'exception', '__version__')


Test patch:
diff --git a/doc/example/pytest.rst b/doc/example/pytest.rst
index 521c741d..f871090d 100644
--- a/doc/example/pytest.rst
+++ b/doc/example/pytest.rst
@@ -95,6 +95,17 @@ importable from somewhere then your ``pytest`` invocation may end up
 importing the package from the checkout directory rather than the
 installed package.
 
+This issue may be characterised by pytest test-collection error messages, in python 3.x environments, that look like:
+
+.. code-block:: shell
+
+    import file mismatch:
+    imported module 'myproj.foo.tests.test_foo' has this __file__ attribute:
+      /home/myuser/repos/myproj/build/lib/myproj/foo/tests/test_foo.py
+    which is not the same as the test file we want to collect:
+      /home/myuser/repos/myproj/myproj/foo/tests/test_foo.py
+    HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
+
 There are a few ways to prevent this.
 
 With installed tests (the tests packages are known to ``setup.py``), a
diff --git a/tests/test_z_cmdline.py b/tests/test_z_cmdline.py
index 1a38001b..746032cb 100644
--- a/tests/test_z_cmdline.py
+++ b/tests/test_z_cmdline.py
@@ -2,7 +2,6 @@ import os
 import platform
 import re
 import subprocess
-import sys
 
 import py
 import pytest
@@ -901,6 +900,5 @@ def test_tox_quickstart_script():
 
 
 def test_tox_cmdline(monkeypatch):
-    monkeypatch.setattr(sys, 'argv', ['caller_script', '--help'])
     with pytest.raises(SystemExit):
-        tox.cmdline()
+        tox.cmdline(['caller_script', '--help'])