Comments (18)
This is not related to C-extensions. I don't know why you keep bringing it up. It's also not related to relative imports.
If DSO module is imported from some pyton file by import .foo
it needs to be located at the same directory where is that file.
pep517 AFAIK do not support building module in-place to put linked DSO where is .py file.
On packaging as far as someone don't want to use venv it meas that it cannot be used methodology which I've described on top of this ticket.
BTW:
We don't want accidental imports from the source directory.
As long as is used pytest wrapper script instead python -m pytest
on pytest execution is not used module code from source tree (python -m foo
adds to sys.paths
current directory). Only bits which are used are test suite files (test*py files found by pytest on scanning units).
Please have look on your CI
multidict/.github/workflows/ci-cd.yml
Line 298 in 8a591ca
in other words you are exposing yourself on that kind of situation.
It was many times repeated on pytest forum to NOT use
python -m pytest
.Another thing about that line. Instead passing
tests
as param better is to have defined testpaths
in pytest settings (if it is already defined that param may be redundant here).from multidict.
Just checked and this module has some DSOs and looks like python code uses relative imports which always causes that kind of issues.
Will try to prepare patch which removes use relative imports and test is it help.
from multidict.
No it did not helped 🤔
Nevertheless using relative imports is nothing more than asking for troubles.
Here is my patch
--- a/multidict/_multidict_py.py
+++ b/multidict/_multidict_py.py
@@ -3,7 +3,7 @@
from array import array
from collections import abc
-from ._abc import MultiMapping, MutableMultiMapping
+from multidict._abc import MultiMapping, MutableMultiMapping
_marker = object()
--- a/multidict/_compat.py
+++ b/multidict/_compat.py
@@ -9,6 +9,6 @@
if USE_EXTENSIONS:
try:
- from . import _multidict # type: ignore[attr-defined] # noqa: F401
+ from multidict import _multidict # type: ignore[attr-defined] # noqa: F401
except ImportError:
USE_EXTENSIONS = False
--- a/multidict/__init__.py
+++ b/multidict/__init__.py
@@ -5,8 +5,8 @@
several values for the same key.
"""
-from ._abc import MultiMapping, MutableMultiMapping
-from ._compat import USE_EXTENSIONS
+from multidict._abc import MultiMapping, MutableMultiMapping
+from multidict._compat import USE_EXTENSIONS
__all__ = (
"MultiMapping",
@@ -26,7 +26,7 @@
try:
if not USE_EXTENSIONS:
raise ImportError
- from ._multidict import (
+ from multidict._multidict import (
CIMultiDict,
CIMultiDictProxy,
MultiDict,
@@ -35,7 +35,7 @@
istr,
)
except ImportError: # pragma: no cover
- from ._multidict_py import (
+ from multidict._multidict_py import (
CIMultiDict,
CIMultiDictProxy,
MultiDict,
Please let me know if you want this as PR.
from multidict.
This is not a problem. The tests use -I
which drops your custom $PYTHONPATH
. If you install properly, this won't be happening.
from multidict.
Another though .. why those units are trying to import DSOs modules from python command line?
They've already have been tested by other units that it is possible to import them 🤔
from multidict.
Because circular imports must be tested in isolation and not rely on import caching from other tests.
from multidict.
This is not a problem. The tests use
-I
which drops your custom$PYTHONPATH
. If you install properly, this won't be happening.
Procedure which I've described opening ticket is typically used on packaging python modules as rpm packages. 😞
In other words those units are breaking "testing as installed" methodology 🤔
from multidict.
Also, I have no idea what you mean by DSO.
from multidict.
In other words those units are breaking \ñ"testing as installed" methodology 🤔
"testing as installed" is exactly what said tests are doing. Your tests are wrong and test "as injected by an arbitrary env var", which is different. We don't want accidental imports from the source directory.
from multidict.
Because circular imports must be tested in isolation and not rely on import caching from other tests.
IIRC cruelty pytest always test circular imports 🤔
This is why none of the other modules test suites are doing what those units here are trying to do.
from multidict.
Also, I have no idea what you mean by DSO.
DSO stands for Dynamic Shared Object.
from multidict.
This is why none of the other modules test suites are doing what those units here are trying to do.
That's entirety untrue. Many of my projects do this. Moreover, I borrowed the idea from pytest's own test suite.
from multidict.
python code uses relative imports which always causes that kind of issues.
This is also totally false, by the way.
from multidict.
This is also totally false, by the way.
Can I read somewhere about that and/or can you explain that? 🤔
AFAIK uses relative imports causes:
- additional syscall to obtain current directory
- breaks testing on typical build procedures used on packaging causing to use additional venvs to test module code/DSOs.
from multidict.
That's entirety untrue. Many of my projects do this. Moreover, I borrowed the idea from pytest's own test suite.
I have packaged ~1.24k modules as rpm packages. Many of them comes with own DSOs as well.
If that methodology is so widely spread I would be able to observe something which you have here in those test unis.
So far this case is first one and I must admit that I'm testing almost those modules using pytest (+99%)
[tkloczko@pers-jacek SPECS]$ grep -l ^%pytest python-*.spec|wc -l; ls -1 python-*.spec|wc -l
1220
1238
I have as well multiple of your modules
[tkloczko@pers-jacek SPECS]$ grep https://github.com/aio-libs/ *spec -l
python-aiobotocore.spec
python-aiohttp-cors.spec
python-aiohttp.spec
python-aiopg.spec
python-aioredis.spec
python-aiosignal.spec
python-async-lru.spec
python-async-timeout.spec
python-frozenlist.spec
python-multidict.spec
python-pytest-aiohttp.spec
python-sphinxcontrib-asyncio.spec
python-yarl.spec
so it is a bit odd that only here I was able to spot failing units on checking circular dependencies methodology which is used here.
I have already multiple tickets opened in your repos
[tkloczko@pers-jacek SPECS]$ grep https://github.com/aio-libs/ *spec |grep BUG
python-aiobotocore.spec:# BUG: pytest fais https://github.com/aio-libs/aiobotocore/issues/965
python-aiohttp-cors.spec:# BUG: test suite fails https://github.com/aio-libs/aiohttp-cors/issues/383
python-aiohttp.spec:# BUG: pytest fais https://github.com/aio-libs/aiohttp/issues/7255
python-aiohttp.spec:# BUG: sphinx fails https://github.com/aio-libs/aiohttp/issues/7230
python-aiopg.spec:# BUG: sphinx fails https://github.com/aio-libs/aiopg/issues/898
python-aioredis.spec:# BUG: pytest is https://github.com/aio-libs/aioredis-py/issues/1406
python-async-timeout.spec:# BUG: test suite warnings https://github.com/aio-libs/async-timeout/issues/203
python-frozenlist.spec:# BUG: sphinx fails https://github.com/aio-libs/frozenlist/issues/570
python-sphinxcontrib-asyncio.spec:# BUG: missing test suite? https://github.com/aio-libs/sphinxcontrib-asyncio/issues/9
python-yarl.spec:# BUG: build fails https://github.com/aio-libs/yarl/issues/969
python-yarl.spec:# BUG: sphinx is failing https://github.com/aio-libs/yarl/issues/970
and I do not remember anything similar (.. maybe my memory tricks me).
from multidict.
python code uses relative imports which always causes that kind of issues.
This is also totally false, by the way.
I many in this case I've been trying to tell that generally use relative imports causes problems with importing modules on use "test as installed" methodology used on packaging.
from multidict.
This is not related to C-extensions. I don't know why you keep bringing it up. It's also not related to relative imports. As I explained earlier, this is because -I
is incompatible with setting env vars externally as it prevents them from leaking into the subprocess invoked during testing.
You can either patch out that option or start installing the library into the site-packages of your test env. These are very simple instructions to follow. I don't have anything else to add.
from multidict.
python code uses relative imports which always causes that kind of issues.
This is also totally false, by the way.
I many in this case I've been trying to tell that generally use relative imports causes problems with importing modules on use "test as installed" methodology used on packaging.
I don't think you understand how imports work but I also don't have time to educate you so you'll just have to take my word for it 🤷♂️
from multidict.
Related Issues (20)
- CIMultiDict: No overload variant of "get" of "Mapping" matches argument type "str" HOT 2
- Wheels for CPython 3.11 HOT 1
- Enhancement: `to_dict` method HOT 1
- Equality operator HOT 6
- Cibuild wheel setup is broken HOT 3
- Fail to build with Python 3.13 HOT 7
- tests/test_mutable_multidict.py::TestCIMutableMultiDict::test_add[multidict._multidict] segfaults on py3.12 HOT 3
- publish purepython/universal wheel? HOT 3
- Build wheels for Python 3.12 HOT 28
- segmentation fault on getall HOT 3
- `MultiDict.copy` returns a `MultiDict` instance when a subclass' `.copy` method is used HOT 4
- [TODO] Hit 100% coverage in `multidict/_multidict_base.py` HOT 2
- [TODO] Migrate `tests/gen_pickles.py` into a pytest fixture HOT 5
- [TODO] Get rid of the disabled MyPy error codes
- Unable to `pip install multidict` with `gcc-14` HOT 21
- [TODO] Start running MyPy against the `multidict/` directory
- [TODO] Revert 19d0511fcebc75cc1e47cf1d71207ac2a28e6e03
- Failing tests test_no_warnings and test_c_extension_preferred_by_default HOT 3
- Case-insensitivity of keys doesn't extend to set operations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multidict.