Skip to content

Test suite needs to be updated for py.test 3.x #5277

Description

@astrofrog

At the moment, our test suite fails if using pytest 3.x. Of course, we're not seeing that in the CI because we use the (old) bundled version of pytest 3.x, so this isn't too urgent. But to see the failures, you can do:

python setup.py build_ext --inplace
py.test astropy

which gives:

========================================================== ERRORS ===========================================================
_____________________________________________________ ERROR collecting  _____________________________________________________
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/main.py:570: in gethookproxy
    return self._fs2hookproxy[fspath]
E   KeyError: local('/Users/tom/Dropbox/Code/Astropy/astropy/astropy/table/tests')

During handling of the above exception, another exception occurred:
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/config.py:301: in _getconftestmodules
    return self._path2confmods[path]
E   KeyError: local('/Users/tom/Dropbox/Code/Astropy/astropy/astropy/table/tests')

During handling of the above exception, another exception occurred:
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/config.py:332: in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local('/Users/tom/Dropbox/Code/Astropy/astropy/astropy/table/tests/conftest.py')

During handling of the above exception, another exception occurred:
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/config.py:338: in _importconftest
    mod = conftestpath.pyimport()
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/py/_path/local.py:650: in pyimport
    __import__(modname)
astropy/table/__init__.py:28: in <module>
    from .column import Column, MaskedColumn
astropy/table/column.py:15: in <module>
    from ..utils.console import color_print
astropy/utils/console.py:29: in <module>
    from IPython import get_ipython
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/__init__.py:48: in <module>
    from .core.application import Application
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/core/application.py:25: in <module>
    from IPython.core.profiledir import ProfileDir, ProfileDirError
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/core/profiledir.py:29: in <module>
    class ProfileDir(LoggingConfigurable):
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/core/profiledir.py:52: in ProfileDir
    `profile` option.""",
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/traitlets/traitlets.py:421: in __init__
    DeprecationWarning, stacklevel=stacklevel)
E   DeprecationWarning: metadata {'config': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')

During handling of the above exception, another exception occurred:
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/py/_path/common.py:332: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/py/_path/common.py:378: in gen
    for p in self.gen(subdir):
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/py/_path/common.py:367: in gen
    dirs = self.optsort([p for p in entries
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/py/_path/common.py:368: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/main.py:672: in _recurse
    ihook = self.gethookproxy(path)
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/main.py:575: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/config.py:315: in _getconftestmodules
    mod = self._importconftest(conftestpath)
/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/_pytest/config.py:340: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: DeprecationWarning("metadata {'config': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')",)
E     File "/Users/tom/Dropbox/Code/Astropy/astropy/astropy/table/__init__.py", line 28, in <module>
E       from .column import Column, MaskedColumn
E     File "/Users/tom/Dropbox/Code/Astropy/astropy/astropy/table/column.py", line 15, in <module>
E       from ..utils.console import color_print
E     File "/Users/tom/Dropbox/Code/Astropy/astropy/astropy/utils/console.py", line 29, in <module>
E       from IPython import get_ipython
E     File "/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/__init__.py", line 48, in <module>
E       from .core.application import Application
E     File "/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/core/application.py", line 25, in <module>
E       from IPython.core.profiledir import ProfileDir, ProfileDirError
E     File "/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/core/profiledir.py", line 29, in <module>
E       class ProfileDir(LoggingConfigurable):
E     File "/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/IPython/core/profiledir.py", line 52, in ProfileDir
E       `profile` option.""",
E     File "/Users/tom/miniconda3/envs/dev35/lib/python3.5/site-packages/traitlets/traitlets.py", line 421, in __init__
E       DeprecationWarning, stacklevel=stacklevel)
================================================== pytest-warning summary ===================================================
WC1 None [pytest] section in setup.cfg files is deprecated, use [tool:pytest] instead.
WC1 None pytest_funcarg__cov: declaring fixtures using "pytest_funcarg__" prefix is deprecated and scheduled to be removed in pytest 4.0.  Please remove the prefix and use the @pytest.fixture decorator instead.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================== 2 pytest-warnings, 1 error in 3.93 seconds =========================================

Activity

  1. changed the title [-]Test suite needs to be updated for pytest 3.x[/-] [+]Test suite needs to be updated for py.test 3.x[/+] on Aug 29, 2016
  2. pllim commented on Aug 30, 2016

    @pllim
    Member

    EDIT: The results below are generated after I changed [pytest] to [tool:pytest] in setup.cfg, as suggested above.

    Wow...

    8242 passed, 118 skipped, 37 xfailed, 721 pytest-warnings, 223 error in 308.78 seconds
    

    Log attached (no --remote-data):
    ztestlog.txt

  3. pllim commented on Nov 2, 2016

    @pllim
    Member

    Note: For another project using Astropy package template, .. doctest-skip-all directive no longer works under pytest 3.x as well.

  4. eteq commented on Nov 2, 2016

    @eteq
    Member

    Note that there's a suspicion from #5435 that a change in pytest 3.x altered how defaults are interpreted by getoption and similar pytest functions. This does not appear to be documented in the pytest 3.x docs (😡 ), but it may address some of this...

  5. bsipocz commented on Nov 23, 2016

    @bsipocz
    Member

    Appveyor breakage of astropy-helpers is also due to pytest 3.x (astropy/astropy-helpers#265 ). While the workaround there is super simple, I'm thinking about to pin the version number of pytest to the one that gets bundled into astropy to be a bit more self consistent.

  6. mhvk commented on Nov 23, 2016

    @mhvk
    Contributor

    Once we fix things, we should perhaps use latest pytest for the allowed-to-fail run (with numpy-dev and remote-data).

  7. bsipocz commented on Nov 23, 2016

    @bsipocz
    Member

    OK, the helpers failure is a red herring, but the pytest behaviour is indeed changed. So the failure was within ci-helpers and that got fixed today.
    The new puzzling issue is that astropy-helpers should have never picked up the ci-helpers test file and indeed it doesn't do it in travis only on appveyor.

  8. mhvk commented on Jan 8, 2017

    @mhvk
    Contributor

    While trying to investigate, I wanted to just use regular commands for testing so I could focus on specific packages. This, it turns out, was foreseen: one can just do

    export ASTROPY_USE_SYSTEM_PYTEST=1
    python3 setup.py test -P ...
    
  9. mhvk commented on Jan 8, 2017

    @mhvk
    Contributor

    There seem to be some different failures:

    • tests using the yield structure are deprecated; these are easy to fix, and @kelle started some fixes for wcs -- I have an additional one for units.
    • for doctests, the output sometimes no longer has line breaks that used to be present.
    • .. doctest-skip seems to get ignored (both individual and whole-file).

    EDIT: Fixed in PRs mentioned here.

  10. mhvk commented on Jan 9, 2017

    @mhvk
    Contributor

    OK, so with #5678 and #5682 merged, the first item on the above little list is checked off. Now need to understand why the output changes (different line length assumed?) and why doctest-skip no longer works...

  11. pllim commented on Jan 10, 2017

    @pllim
    Member

    @mhvk , I spent a good few hours trying to understand the doctest failure but got nowhere. I tried inserting print statements but they don't work with pytest, as it suppresses print outputs, I think. There is no traceback, just some obscure deprecation warnings. And no clear documented translation guide for those deprecations. 😰

  12. astrofrog commented on Jan 10, 2017

    @astrofrog
    MemberAuthor

    @pllim - you can run pytest with the -s option to see the output of print statements.

  13. pllim commented on Jan 11, 2017

    @pllim
    Member

    Some warnings are due to a bug in pytest 3.0.5, see pytest-dev/pytest#2118, although that still does not explain why doctest is not skipping some files/snippets as it should. FYI.

    Update: To avoid those warnings, pin pytest to 3.0.4 until the bug is fixed. Mind you, doctest still does not work properly but we will have less warnings to worry about.

  14. mhvk commented on Jan 12, 2017

    @mhvk
    Contributor

    I've been trying to narrow down a bit. A first conclusion is that the problem only occurs for text files, not for source files (modules; e.g., __doctest_skip__ in *.py files does work). A second is that the options we pass on, in particular NORMALIZE_WHITESPACE in pytest_plugins.pytest_configure does not seem to get used for *.rst files.
    ...
    ...
    ...
    Looking in more detail, the main problem seems to be that there is no collect method defined for DocTestTextfilePlus. Indeed, by adding a collect method following the pytest DoctestTextfile class, I can get the tests to pass! (well, minus some annoying vo tests, but what's new...) See #5688.

  15. mhvk commented on Jan 19, 2017

    @mhvk
    Contributor

    Closing this, since with #5688 astropy now works well with pytest 3.x.

  16. cdeil commented on Aug 3, 2017

    @cdeil
    Member

    This just now appeared, I think because our CI switched to the recently released pytest 3.2:
    https://travis-ci.org/hipspy/hips/jobs/260162492#L1211

    INTERNALERROR> AttributeError: 'DocTestTextfilePlus' object has no attribute '_location'
    

    Should I file a new issue about this? In which tracker?

  17. bsipocz commented on Aug 3, 2017

    @bsipocz
    Member

    We're on it. Long story short it's not yet clear whether it's a bug in our plugin or in pytest so we need to limit the version number of pytest for now, I'm waiting for the builds to pass on ci-helpers (astropy/ci-helpers#222).

    pytest-dev/pytest#2651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions