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

Cache not respecting cache_dir config option #3260

Closed
dbeckwith opened this issue Feb 24, 2018 · 11 comments · Fixed by #3267
Closed

Cache not respecting cache_dir config option #3260

dbeckwith opened this issue Feb 24, 2018 · 11 comments · Fixed by #3267
Assignees
Labels
good first issue easy issue that is friendly to new contributor plugin: cache related to the cache builtin plugin type: bug problem that needs to be addressed

Comments

@dbeckwith
Copy link

I'm trying to direct all test and coverage output to a single .cache directory in my project, but pytest won't respect the cache_dir option I'm setting to .cache/pytest and keeps creating .pytest_cache instead. This used to work fine in another project with pytest 3.3.0.

$ cat setup.cfg
[pycodestyle]
ignore = E123,E126,E501

[tool:pytest]
testpaths = tests
cache_dir = .cache/pytest

[coverage:run]
branch = True
source = snlint
data_file = .cache/cov/coverage

[coverage:report]
show_missing = True
sort = Name
exclude_lines =
    # Have to re-enable the standard pragma
    pragma: no cover

    # Don't complain about missing debug-only code:
    def __repr__
    if config\.debug

    # Don't complain if tests don't hit defensive assertion code:
    raise AssertionError
    raise NotImplementedError
    assert 0
    assert False

    # Don't complain if non-runnable code isn't run:
    if 0:
    if False:
    if __name__ == .__main__.:

[coverage:html]
directory = .cache/cov/cov_html

[coverage:xml]
output = .cache/cov/cov.xml

$ pytest \
	-c setup.cfg \
	-vv \
	--cov snlint \
	--cov-config setup.cfg \
	--cov-report html \
	--cov-report xml \
    	--cov-report term-missing
============================================================================================================================================================================ test session starts ============================================================================================================================================================================
platform linux -- Python 3.6.3, pytest-3.4.1, py-1.5.2, pluggy-0.6.0 -- /home/sonaxaton/.local/share/virtualenvs/snlint-so_H9yU2/bin/python3.6
cachedir: .pytest_cache
rootdir: /home/sonaxaton/Dropbox/Programming/python/snlint, inifile: setup.cfg
plugins: cov-2.5.1
...

$ pip list
Package          Version
---------------- -------
attrs            17.4.0 
click            6.7    
coverage         4.5.1  
pip              9.0.1  
pluggy           0.6.0  
py               1.5.2  
pycodestyle      2.3.1  
pytest           3.4.1  
pytest-cov       2.5.1  
setuptools       38.5.1 
six              1.11.0 
sortedcontainers 1.5.9  
wheel            0.30.0 
@nicoddemus nicoddemus added type: bug problem that needs to be addressed plugin: cache related to the cache builtin plugin good first issue easy issue that is friendly to new contributor labels Feb 26, 2018
@feuillemorte
Copy link
Contributor

I take it :)

@nicoddemus
Copy link
Member

Cool @feuillemorte, thanks! (In the future feel free to assign yourself to the issues if you want 😉)

@feuillemorte
Copy link
Contributor

reproduced only with option "-c setup.cfg"

@feuillemorte
Copy link
Contributor

feuillemorte commented Feb 26, 2018

Seems that problem is in setup.cfg file:

[tool:pytest]
testpaths = tests
cache_dir = .cache/pytest

[tool:pytest] instead of [pytest]. If you fix it it will work fine:

cachedir: .cache/pytest
rootdir: /home/username/github/pytest-dev/pytest/pytest_3260, inifile: tests/setup_new.cfg

The problem is here:

pytest/_pytest/config.py

Lines 1326 to 1349 in 44fa5a7

def determine_setup(inifile, args, warnfunc=None):
dirs = get_dirs_from_args(args)
if inifile:
iniconfig = py.iniconfig.IniConfig(inifile)
try:
inicfg = iniconfig["pytest"]
except KeyError:
inicfg = None
rootdir = get_common_ancestor(dirs)
else:
ancestor = get_common_ancestor(dirs)
rootdir, inifile, inicfg = getcfg([ancestor], warnfunc=warnfunc)
if rootdir is None:
for rootdir in ancestor.parts(reverse=True):
if rootdir.join("setup.py").exists():
break
else:
rootdir, inifile, inicfg = getcfg(dirs, warnfunc=warnfunc)
if rootdir is None:
rootdir = get_common_ancestor([py.path.local(), ancestor])
is_fs_root = os.path.splitdrive(str(rootdir))[1] == '/'
if is_fs_root:
rootdir = ancestor
return rootdir, inifile, inicfg or {}

Code goes in the first "if" and not calls getcfg function (which parses [tool:pytest] section) because inifilename defined by "-c" option:

def determine_setup(inifile, args, warnfunc=None):
    dirs = get_dirs_from_args(args)
    print('INI', inifile)

prints me

INI tests/setup_new.cfg

@nicoddemus is it a bug or smth was changed from 3.3.0 version?

@nicoddemus
Copy link
Member

@feuillemorte thanks for the investigation! Now I see that this is actually a duplicate of #1831.

I think we should change that line to inicfg = iniconfig["tool:pytest"] when we are dealing with .cfg files, something like:

         section = 'tool:pytest' if inifile.ext == '.cfg' else 'pytest'
         try: 
             inicfg = iniconfig[section] 
         except KeyError: 
             inicfg = None 

@feuillemorte
Copy link
Contributor

feuillemorte commented Feb 26, 2018

But section might be [tool:pytest] or [pytest] in .cfg file, isn't it?

@nicoddemus
Copy link
Member

Oh you are right, so we need to have a list of possible sections then, and check each one.

@dbeckwith
Copy link
Author

dbeckwith commented Feb 26, 2018

The current docs on this are unclear or pointing towards it being [tool:pytest], hence my confusion. I think they need to be updated as well to reflect whatever comes out of this. Also, [tool:pytest] should be preserved for backwards-compatibility.

@nicoddemus
Copy link
Member

nicoddemus commented Feb 27, 2018

@dbeckwith you are right, just to be clear:

EDIT: the bug here is that -c setup.cfg is not recognizing [tool:pytest], when in fact it should.

@dbeckwith
Copy link
Author

Okay, and the I guess the issue I was running into was that specifying the file with -c made it assume it was just some random config file and not setup.cfg?

@nicoddemus
Copy link
Member

Okay, and the I guess the issue I was running into was that specifying the file with -c made it assume it was just some random config file and not setup.cfg?

Exactly. If you don't pass -c then your example works as @feuillemorte mentioned, but this is a bug that we should fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor plugin: cache related to the cache builtin plugin type: bug problem that needs to be addressed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants