Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move pytest options to pytest inifile #76

Merged
merged 1 commit into from
Jan 11, 2019

Conversation

vxgmichel
Copy link
Contributor

A naive pytest run currently fails with the following trace:

$ pytest
==================================== test session starts =====================================
platform linux -- Python 3.7.2, pytest-4.1.0, py-1.7.0, pluggy-0.8.0
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/vinmic/pytest-trio/.hypothesis/examples')
rootdir: /home/vinmic/pytest-trio, inifile:
plugins: xdist-1.25.0, trio-0.5.1, forked-0.2, cov-2.6.1, hypothesis-3.88.3
collected 0 items / 1 errors                                                                 

=========================================== ERRORS ===========================================
_____________________________________ ERROR collecting  ______________________________________
../miniconda/lib/python3.7/site-packages/_pytest/config/__init__.py:427: in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local('/home/vinmic/pytest-trio/pytest_trio/_tests/conftest.py')

During handling of the above exception, another exception occurred:
../miniconda/lib/python3.7/site-packages/_pytest/config/__init__.py:433: in _importconftest
    mod = conftestpath.pyimport()
../miniconda/lib/python3.7/site-packages/py/_path/local.py:688: in pyimport
    raise self.ImportMismatchError(modname, modfile, self)
E   py._path.local.LocalPath.ImportMismatchError: ('pytest_trio._tests.conftest', '/home/vinmic/miniconda/lib/python3.7/site-packages/pytest_trio/_tests/conftest.py', local('/home/vinmic/pytest-trio/pytest_trio/_tests/conftest.py'))

During handling of the above exception, another exception occurred:
../miniconda/lib/python3.7/site-packages/py/_path/common.py:377: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
../miniconda/lib/python3.7/site-packages/py/_path/common.py:429: in gen
    for p in self.gen(subdir):
../miniconda/lib/python3.7/site-packages/py/_path/common.py:418: in gen
    dirs = self.optsort([p for p in entries
../miniconda/lib/python3.7/site-packages/py/_path/common.py:419: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
../miniconda/lib/python3.7/site-packages/_pytest/main.py:635: in _recurse
    ihook = self.gethookproxy(dirpath)
../miniconda/lib/python3.7/site-packages/_pytest/main.py:452: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
../miniconda/lib/python3.7/site-packages/_pytest/config/__init__.py:411: in _getconftestmodules
    mod = self._importconftest(conftestpath)
../miniconda/lib/python3.7/site-packages/_pytest/config/__init__.py:450: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: (local('/home/vinmic/pytest-trio/pytest_trio/_tests/conftest.py'), (<class 'py._path.local.LocalPath.ImportMismatchError'>, ImportMismatchError('pytest_trio._tests.conftest', '/home/vinmic/miniconda/lib/python3.7/site-packages/pytest_trio/_tests/conftest.py', local('/home/vinmic/pytest-trio/pytest_trio/_tests/conftest.py')), <traceback object at 0x7fc3575b6b08>))
!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!
================================== 1 error in 0.16 seconds ===================================

This PR moves the pytest options defined in ci/travis.sh to a pytest inifile. I had to create a new pytest.ini file since pyproject.toml isn't supported by pytest yet. This shouldn't break the CI (hopefully).

@codecov
Copy link

codecov bot commented Jan 11, 2019

Codecov Report

Merging #76 into master will increase coverage by 0.21%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
+ Coverage   99.34%   99.56%   +0.21%     
==========================================
  Files          19       19              
  Lines         461      461              
  Branches       43       43              
==========================================
+ Hits          458      459       +1     
  Misses          2        2              
+ Partials        1        0       -1
Impacted Files Coverage Δ
pytest_trio/plugin.py 98.94% <0%> (+0.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5df0bde...bae1fbc. Read the comment docs.

@pquentin
Copy link
Member

Looks good to me, thanks!

(Not sure why the coverage changes...)

@pquentin pquentin merged commit e828788 into python-trio:master Jan 11, 2019
@njsmith
Copy link
Member

njsmith commented Jan 11, 2019

I don't understand what that error is saying, or why this change fixes it. Can anyone explain?

Is it: pytest was finding two copies of pytest-trio, one in the current directory and one in site-packages, and getting confused by that? And creating a pytest.ini file forces pytest to treat that directory as the root?

Does the contents of the file matter? The full options there are good for CI where you can't easily re-run tests, but not what I normally like for local runs...

Or is it the --pyargs pytest_trio that's crucial?

Does the CI's trick of running from an empty subdirectory to test the installed version, instead of the version in the source tree, still work?

@vxgmichel
Copy link
Contributor Author

vxgmichel commented Jan 12, 2019

Or is it the --pyargs pytest_trio that's crucial?

Yes, as far as I can tell.

And creating a pytest.ini file forces pytest to treat that directory as the root?

It does, although this doesn't influence the import mechanism.

I just realized the rootdir is not used by coverage to find the .coveragerc file, so we have to add --cov-config=../.coveragerc back to the ci script.

Does the CI's trick of running from an empty subdirectory to test the installed version, instead of the version in the source tree, still work?

Yes. Actually, pytest does not add the current directory to sys.path, unless python -m pytest is used.

EDIT: I just realized it does add the root of the repository to sys.path because the tests are part of a test package importable as pytest_trio._tests.

The full options there are good for CI where you can't easily re-run tests, but not what I normally like for local runs...

I agree. I can make a new PR from the following patch:

diff --git a/ci/travis.sh b/ci/travis.sh
index 6cee6a7..201cdb5 100755
--- a/ci/travis.sh
+++ b/ci/travis.sh
@@ -92,7 +92,7 @@ else
     mkdir empty
     cd empty
 
-    pytest
+    pytest -r a --verbose --cov --cov-config=../.coveragerc
 
     bash <(curl -s https://codecov.io/bash)
 fi
diff --git a/pytest.ini b/pytest.ini
index e7e9beb..e31f910 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,2 +1,2 @@
 [pytest]
-addopts = -W error -ra -v --pyargs pytest_trio --verbose --cov
+addopts = -W error --pyargs pytest_trio

I rushed it a bit, sorry about that. In the long run, it could be nice to use tox or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants