Skip to content

WIP: fix #4507 and ensure our modules have no warnings for general import #4510

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

Closed
wants to merge 22 commits into from

Conversation

RonnyPfannschmidt
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt commented Dec 5, 2018

closes #4507

@codecov
Copy link

codecov bot commented Dec 5, 2018

Codecov Report

Merging #4510 into master will decrease coverage by 3.02%.
The diff coverage is 95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4510      +/-   ##
==========================================
- Coverage   96.16%   93.14%   -3.03%     
==========================================
  Files         117      118       +1     
  Lines       25864    25906      +42     
  Branches     2498     2500       +2     
==========================================
- Hits        24873    24129     -744     
- Misses        690     1437     +747     
- Partials      301      340      +39
Impacted Files Coverage Δ
src/_pytest/config/__init__.py 94.13% <100%> (-0.49%) ⬇️
src/_pytest/helpconfig.py 97.58% <100%> (+0.05%) ⬆️
src/_pytest/terminal.py 90.39% <100%> (-2.64%) ⬇️
src/_pytest/tmpdir.py 100% <100%> (ø) ⬆️
src/_pytest/setuponly.py 95.74% <100%> (ø) ⬆️
src/_pytest/doctest.py 93.7% <100%> (-2.93%) ⬇️
src/_pytest/pastebin.py 87.71% <100%> (ø) ⬆️
src/_pytest/setupplan.py 100% <100%> (ø) ⬆️
src/_pytest/junitxml.py 95.82% <100%> (ø) ⬆️
src/_pytest/stepwise.py 96.55% <100%> (ø) ⬆️
... and 46 more

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 5ecac3c...2d1d313. Read the comment docs.

@johnthagen
Copy link

@RonnyPfannschmidt Will this also solve #1403?

@RonnyPfannschmidt
Copy link
Member Author

@johnthagen correct, its one of the warnings i sorted out

@RonnyPfannschmidt
Copy link
Member Author

@johnthagen wait, actually it isnt, i only contained that warning to the assertion module

we will leave it in place until we drop python 2.7 support in the mainline as the implementation effort is a mess otherwise



def _get_modules():
for module in vars(_pytest).values():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnthagen
Copy link

johnthagen commented Dec 5, 2018

@RonnyPfannschmidt Do you think we could fix #1403 by using a warning filter?

with warnings.catch_warnings():
    warnings.filterwarnings('ignore', category=DeprecationWarning)
    import imp

@asottile
Copy link
Member

asottile commented Dec 5, 2018

I think the actual fix here needs to be to factor out usage of imp in python 3.x

Looks like we have a few usages, all in the assertion module:

$ grep 'imp\.' -- !$
grep 'imp\.' -- src/_pytest/assertion/rewrite.py
    PYTEST_TAG = imp.get_tag() + "-PYTEST"
        return imp.find_module(name, path)
            if tp == imp.PY_COMPILED:
                        fn = imp.source_from_cache(fn)
            elif tp != imp.PY_SOURCE:
        shown that the call to imp.find_module (inside of the find_module
            # I wish I could just call imp.load_compiled here, but __file__ has to
            mod = sys.modules[name] = imp.new_module(name)
        return tp == imp.PKG_DIRECTORY
    # sometime to be able to use imp.load_compiled to load them. (See
            fp.write(imp.get_magic())
            or data[:4] != imp.get_magic()

@johnthagen
Copy link

Python 2.7 has a small compatibility version of importlib. Perhaps that can help?

@asottile
Copy link
Member

asottile commented Dec 5, 2018

Python 2.7 has a small compatibility version of importlib. Perhaps that can help?

unfortunately it does not, pytest does code rewriting and builds modules + pyc files which is very much out of the scope of importlib.import_module (which, isn't actually a super helpful function given __import__ is a builtin!)

@RonnyPfannschmidt
Copy link
Member Author

importlib2 might be applicable

@asottile
Copy link
Member

asottile commented Dec 5, 2018

Seems "use at your own risk beta" -- maybe not the best choice here?

@johnthagen
Copy link

Yeah, looks like importlib2 hasn't been updated since 2014, which probably isn't a good sign.

@Zac-HD
Copy link
Member

Zac-HD commented Dec 7, 2018

@RonnyPfannschmidt - can you paste Closes #1403 and closes #4507 into the top comment, to automatically close those issues when this PR is merged?

It's also a machine-readable link between issues and related PRs that e.g. the refined github extension can pick up on, which means I can see whether a given issue has a currently-open PR that will resolve it 😄

Not a big deal, but I've found (and manually closed) a few orphan issues which stayed open long after the fixing PR was merged so we might as well use the tools to avoid that!

@RonnyPfannschmidt
Copy link
Member Author

pushed a merge will have to amend it later on

@RonnyPfannschmidt
Copy link
Member Author

@asottile the usage of distutils.spawn has to go - its importing imp

@asottile
Copy link
Member

@asottile the usage of distutils.spawn has to go - its importing imp

you sure?

$ python3.7 -Werror -c 'import distutils.spawn'
$

@asottile
Copy link
Member

yeah definitely not:

$ find /usr/lib/python3.6/distutils/ -name "*.py" | xargs grep -E '(from|import) imp'
/usr/lib/python3.6/distutils/util.py:import importlib.util
/usr/lib/python3.6/distutils/command/install_lib.py:import importlib.util
/usr/lib/python3.6/distutils/command/build_py.py:import importlib.util

@RonnyPfannschmidt
Copy link
Member Author

@asottile
Copy link
Member

that's virtualenv's fault -- not stdlib: pypa/virtualenv#955

@asottile
Copy link
Member

err -- pypa/virtualenv#555

looks like it's been fixed, upgrade virtualenv and that should poof

# virtualenv bug
"-W", "ignore:the imp:DeprecationWarning:distutils",
"-c", "import " + module_name,
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be combinded with the (very slow) testing/test_modimport.py at least?
I would also like to run these kind of tests in a single CI job only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs # fmt: on again.

@gaborbernat
Copy link
Contributor

@asottile @RonnyPfannschmidt any updates on this? does this requires a restart?

@RonnyPfannschmidt
Copy link
Member Author

i lost track of it, im currently still on my hiatus, but i'l take a look at making this work quickly this week

@RonnyPfannschmidt
Copy link
Member Author

i got started on resolving the rebase artifacts, but right now its unlikely to finish before sometime next week

@gaborbernat
Copy link
Contributor

Thanks for the update!

@RonnyPfannschmidt
Copy link
Member Author

main reason being that i currently do only public opensouce to do a bit of unpacking while the preps for the marriage on saturday are running ^^

@nicoddemus
Copy link
Member

Gratz!

@RonnyPfannschmidt
Copy link
Member Author

i started picking this one up again, i merged around a bit and will squash around soonish to deal with the fallout of this stuff

@@ -10,7 +10,10 @@
from io import UnsupportedOperation
from tempfile import TemporaryFile

import pytest
from .config import hookimpl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why the imports changed, maybe I missed this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the import cycle to pytest

Else we can't import parts of pytest without breaking

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you show me what you mean -- like stacktrace or reproduction or whatnot, I'm not sure I understand (and I don't understand why it's necessary for this PR)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pytest imports from all over the place this preveting isolation, if everything triggers every import then I can't let it effectively tell me what is going on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last stack trace I had if this disappeared a few months ago in a terminal, perhaps I could recreate it when I'm back on that computer

@johnthagen
Copy link

johnthagen commented Oct 1, 2019

I think a new warning has popped up today from attr (#5901):

  File "/home/gitlab-runner/builds/DwvLisya/0/.tox/py36/lib/python3.6/site-packages/_pytest/mark/structures.py", line 370, in <module>
    @attr.s(cmp=False, hash=False)
  File "/home/gitlab-runner/builds/DwvLisya/0/.tox/py36/lib/python3.6/site-packages/attr/_make.py", line 944, in attrs
    eq, order = _determine_eq_order(cmp, eq, order)
  File "/home/gitlab-runner/builds/DwvLisya/0/.tox/py36/lib/python3.6/site-packages/attr/_make.py", line 750, in _determine_eq_order
    warnings.warn(_CMP_DEPRECATION, DeprecationWarning, stacklevel=3)
DeprecationWarning: The usage of `cmp` is deprecated and will be removed on or after 2021-06-01.  Please use `eq` and `order` instead.

@RonnyPfannschmidt
Copy link
Member Author

@asottile the communication around the super-seed leaves me personally with a bad after-taste, i'll reflect on that

@asottile
Copy link
Member

asottile commented Oct 2, 2019

@asottile the communication around the super-seed leaves me personally with a bad after-taste, i'll reflect on that

ah I mostly wanted to get this going again -- and wanted to see if I could find the import error -- no harm intended :(

blueyed added a commit to blueyed/pytest that referenced this pull request Feb 3, 2020
testing/test_meta.py ensures this already as a side effect
(+ tests a few more (`__init__.py` files) and should have been
combined with it right away [1].

1: pytest-dev#4510 (comment)

Ref: pytest-dev@eaa05531e
Ref: pytest-dev@4d31ea831
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.

DeprecationWarning triggered in _pytest.tmpdir use of attr
7 participants