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

Set __package__ to fix import warnings #546

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
3 participants
@jleclanche
Copy link

jleclanche commented Nov 26, 2017

Fixes #495

Also see #415.

@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Nov 26, 2017

Codecov Report

Merging #546 into master will decrease coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #546      +/-   ##
==========================================
- Coverage      92%   91.89%   -0.12%     
==========================================
  Files          33       33              
  Lines        1627     1629       +2     
  Branches      140      140              
==========================================
  Hits         1497     1497              
- Misses         93       95       +2     
  Partials       37       37
Flag Coverage Δ
#dj110 84.77% <100%> (+0.01%) ⬆️
#dj111 85.94% <100%> (-0.11%) ⬇️
#dj18 85.63% <100%> (+0.01%) ⬆️
#dj19 84.65% <100%> (+0.01%) ⬆️
#dj20 84.34% <100%> (+0.01%) ⬆️
#djmaster 84.34% <100%> (+0.01%) ⬆️
#mysql_innodb ?
#mysql_myisam 84.22% <100%> (+0.01%) ⬆️
#postgres 87.66% <100%> (+0.01%) ⬆️
#py27 89.25% <100%> (-0.11%) ⬇️
#py34 84.65% <100%> (+0.01%) ⬆️
#py35 84.77% <100%> (+0.01%) ⬆️
#py36 84.83% <100%> (+0.01%) ⬆️
#sqlite 86.12% <100%> (+0.01%) ⬆️
#sqlite_file 84.65% <100%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pytest_django/plugin.py 86.32% <100%> (+0.04%) ⬆️
pytest_django/fixtures.py 97.41% <100%> (+0.01%) ⬆️
pytest_django_test/settings_mysql_innodb.py 0% <0%> (-100%) ⬇️

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 4145f73...3a80ecf. Read the comment docs.

@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Nov 26, 2017

Codecov Report

Merging #546 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #546      +/-   ##
==========================================
+ Coverage      92%   92.02%   +0.01%     
==========================================
  Files          33       33              
  Lines        1627     1767     +140     
  Branches      140      154      +14     
==========================================
+ Hits         1497     1626     +129     
- Misses         93      103      +10     
- Partials       37       38       +1
Flag Coverage Δ
#dj110 84.77% <100%> (+0.01%) ⬆️
#dj111 86.58% <100%> (+0.53%) ⬆️
#dj18 85.63% <100%> (+0.01%) ⬆️
#dj19 84.65% <100%> (+0.01%) ⬆️
#dj20 84.34% <100%> (+0.01%) ⬆️
#djmaster 84.34% <100%> (+0.01%) ⬆️
#mysql_innodb 84.37% <100%> (+0.11%) ⬆️
#mysql_myisam 84.22% <100%> (+0.01%) ⬆️
#postgres 87.66% <100%> (+0.01%) ⬆️
#py27 89.7% <100%> (+0.33%) ⬆️
#py34 84.65% <100%> (+0.01%) ⬆️
#py35 84.77% <100%> (+0.01%) ⬆️
#py36 84.83% <100%> (+0.01%) ⬆️
#sqlite 86.12% <100%> (+0.01%) ⬆️
#sqlite_file 84.65% <100%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pytest_django/fixtures.py 97.05% <100%> (-0.35%) ⬇️
pytest_django/plugin.py 86.32% <100%> (+0.04%) ⬆️
pytest_django/live_server_helper.py 82.55% <0%> (-7.92%) ⬇️
tests/test_fixtures.py 99.65% <0%> (-0.35%) ⬇️

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 4145f73...3a80ecf. Read the comment docs.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Nov 27, 2017

What warning does it fix?
How is #395 related?

@jleclanche

This comment has been minimized.

Copy link
Author

jleclanche commented Nov 27, 2017

Sorry, typo, it fixes #495

@jleclanche

This comment has been minimized.

Copy link
Author

jleclanche commented Dec 24, 2017

Anyone?

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Dec 25, 2017

It is not clear to me why this is needed, can you elaborate?

Otherwise / in general it seems fine though.

@blueyed blueyed added the enhancement label Dec 25, 2017

@blueyed blueyed added this to the 3.2 milestone Dec 25, 2017

@jleclanche

This comment has been minimized.

Copy link
Author

jleclanche commented Dec 25, 2017

@blueyed It fixes the warnings reported in #495. Running any pytest-django project with PYTHONWARNINGS=all has those in the logs which is quite annoying.

@jleclanche jleclanche changed the title Set __package__ to fix deprecation warnings Set __package__ to fix import warnings Dec 25, 2017

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Dec 25, 2017

@jleclanche
I see, but it is not clear to me why there is this warning in the first place.
I see it when running pytest-django's tests itself, but only when not installing it / setting $PYTHONPATH like it is done in tox.ini.

@jleclanche

This comment has been minimized.

Copy link
Author

jleclanche commented Dec 25, 2017

I suspect it has to do with the way pytest loads plugins.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Dec 25, 2017

Yes.

PYTHONWARNINGS=all triggers displaying them, but pytest -W error does neither display them, nor cause them to be errors.

Stacktrace:

% PYTHONWARNINGS=all p -W error tests/test_unittest.py
…/Vcs/pytest-django/.venv/lib/python3.6/site-packages/_pytest/assertion/rewrite.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
> …/Vcs/pytest-django/pytest_django/plugin.py(18)<module>()
-> from .django_compat import is_django_unittest  # noqa
(Pdb) bt
  …/Vcs/pytest-django/.venv/bin/pytest(11)<module>()
-> sys.exit(main())
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/_pytest/config.py(50)main()
-> config = _prepareconfig(args, plugins)
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/_pytest/config.py(160)_prepareconfig()
-> pluginmanager=pluginmanager, args=args)
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/pluggy/__init__.py(617)__call__()
-> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/pluggy/__init__.py(222)_hookexec()
-> return self._inner_hookexec(hook, methods, kwargs)
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/pluggy/__init__.py(216)<lambda>()
-> firstresult=hook.spec_opts.get('firstresult'),
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/pluggy/callers.py(180)_multicall()
-> res = hook_impl.function(*args)
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/_pytest/config.py(943)pytest_cmdline_parse()
-> self.parse(args)
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/_pytest/config.py(1108)parse()
-> self._preparse(args, addopts=addopts)
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/_pytest/config.py(1071)_preparse()
-> self.pluginmanager.load_setuptools_entrypoints('pytest11')
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/pluggy/__init__.py(397)load_setuptools_entrypoints()
-> plugin = ep.load()
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/pkg_resources/__init__.py(2408)load()
-> return self.resolve()
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/pkg_resources/__init__.py(2414)resolve()
-> module = __import__(self.module_name, fromlist=['__name__'], level=0)
  <frozen importlib._bootstrap>(961)_find_and_load()
  <frozen importlib._bootstrap>(950)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(646)_load_unlocked()
  <frozen importlib._bootstrap>(616)_load_backward_compatible()
  …/Vcs/pytest-django/.venv/lib/python3.6/site-packages/_pytest/assertion/rewrite.py(212)load_module()
-> py.builtin.exec_(co, mod.__dict__)
> …/Vcs/pytest-django/pytest_django/plugin.py(18)<module>()
-> from .django_compat import is_django_unittest  # noqa
(Pdb) n
…/Vcs/pytest-django/pytest_django/plugin.py:18: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from .django_compat import is_django_unittest  # noqa
> …/Vcs/pytest-django/pytest_django/plugin.py(19)<module>()
-> from .fixtures import django_assert_num_queries  # noqa
@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Dec 25, 2017

Filed pytest-dev/pytest#3061 with pytest.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Dec 25, 2017

Can you confirm that it is only an issue / displayed when using -s?

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Jan 9, 2018

Looks like a pytest issue (see pytest-dev/pytest#3061).

Warnings can be ignored (temporary solution): nicoddemus/pytest@3dd24f8.

@jleclanche

This comment has been minimized.

Copy link
Author

jleclanche commented Feb 20, 2018

@blueyed Hey, sorry to get back to this so late but is this PR getting merged? I understand it's not the best fix but I'd really like to get rid of the warnings =/

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Feb 21, 2018

@jleclanche
I'd rather get this fixed properly, especially since the reason for this is still unclear to me.
You can use the workaround from nicoddemus/pytest@3dd24f8.

@blueyed blueyed modified the milestones: 3.2, 3.3 Apr 14, 2018

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Jun 26, 2018

pytest has it fixed by now: pytest-dev/pytest@50a0d4f (not yet released I guess)

Closing this here for now.

Thanks for the PR and discussion of course still!

@blueyed blueyed closed this Jun 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.