python - Pytest and concurrent.futures interacting strangely
问题描述
I am using pytest
to test my project, and I am using concurrent.futures
to add parallelism to some of my algorithms. When I use pytest
without the parallelized code, the tests complete as expected. When I run the parallelized code directly (without pytest
), the code executes as expected. However, when I try to run pytest on parallelized code, some lines importing my project modules, such as
import tools_2d.classes
throw the exception
AttributeError: module 'tools_2d' has no attribute 'classes'
Thus, pytest
and concurrent.futures
seem to be working when used independently, but throw exceptions when used together. It seems that the workers spawned by multiprocessing cannot find my project modules when invoked by pytest. What am I doing wrong?
I am using python 3.9 on Windows. My project has the following structure:
repo
|-- tools_2d
| |-- algorithms.py
| |-- classes.py
| |-- drawing.py
| `-- utils.py
|-- algorithms
| |-- line.py
| `-- region.py
|-- tests
| `-- test_algorithms.py
|-- main.py
|-- storage.py
|-- requirements.txt
`-- ...
解决方案
推荐阅读
- docker - docker 容器中的 TCP 源端口错误
- snakemake - 在配置文件中使用 snakemake.utils 而不使用 conda-not-block-search-path-envvars
- spring-boot - 达到 slowCallRateThreshold 时 Resilience4j 断路器不打开?
- javascript - 使用 Selenium 选择下拉菜单选项 - 下拉菜单仅在将搜索查询输入框后出现
- python - 从多变量正态分布中采样多个元素
- pandas - 良好的霍普金斯分数,但聚类质量差
- arrays - 我将如何动态附加一个 char 的二维数组?
- python - 预训练的word2vec模型的进程之间的共享内存?
- spring-integration - 如何强制 TcpNetClientConnectionFactory 打开连接而不发送消息?
- javascript - 使用 localStorage 实现购物车