PyO3 error

Đang mở
#614 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
testing-qa

Hướng nghiên cứu

Reproduce the failure with test_one.py, folder/init.py, folder/some_module.py, and the stated pytest command and package versions. Start by investigating how the --cov=folder.some_module entry point affects imports, then compare runs with and without --cov and with the listed dependency versions. Done means the cause is established and the reproducer no longer fails or the limitation is documented.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Hello,

I am currently debugging weird issue that happens to us only when using --cov arguments to pytest and only during running tests (not in production with the same code).

Reproducer

I was able to narrow it down for this little setup:
create this structure:

.
├── folder
│   ├── __init__.py
│   └── some_module.py
└── test_one.py

Now, some_module.py is empty.
folder/__init__.py has this content:

`from cryptography.hazmat.primitives import hashes`

test_one.py has this content:

`from cryptography.hazmat.primitives import hashes`

When you run this command (note that in my case the whole directory structure is in /home/vagrant/neto directory):

`PYTHONPATH=$PYTHONPATH:/home/vagrant/neto pytest /home/vagrant/neto/test_one.py --cov=folder.some_module`

you get

ImportError while importing test module '/home/vagrant/neto/test_one.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../.pyenv/versions/3.8.18/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_one.py:2: in <module>
    from cryptography.hazmat.primitives import hashes
../venv/pack/lib/python3.8/site-packages/cryptography/hazmat/primitives/hashes.py:10: in <module>
    from cryptography.hazmat.bindings._rust import openssl as rust_openssl
E   ImportError: PyO3 modules may only be initialized once per interpreter process

explanation

Reasons why I think (though not sure) the problem is in python-cov:

  • you can switch from cryptography.hazmat.primitives import hashes for import jsonschema and you get the into the same error.
  • we dont get any errors in production with the other imported packages.
  • you remove the --cov attribute and it runs without errors.
  • that importError sounds like that it might be caused by the way --cov path is handled internally?

versions

  • python 3.8.18
  • pytest 7.4.2
  • pytest-cov 4.1.0
  • jsonschema 4.19.1, problem doesnt appear when downgrading to 4.17.3
  • cryptography 41.0.4, problem doesnt appear when downgrading to 40.0.2
Ngôn ngữ chính
Python
Star
2.1k
Fork
256
Merge trung bình
6 ngày 10 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pytest-dev/pytest-cov

Tất cả issue của pytest-dev/pytest-cov

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.