В настоящее время я пытаюсь запустить тесты, зависящие от MPI, с помощью pytest-mpi. Я сделал минимальный пример
Код: Выделить всё
# Standard Library Imports
import os
# Third-Party Library Imports
from mpi4py import MPI
import pytest
# Local Library Imports
# Relative Imports
@pytest.mark.mpi()
def test_mpi(tmp_path):
## Initialize MPI
if not MPI.Is_initialized():
MPI.init()
MPI_comm: MPI.Intracomm = MPI.COMM_WORLD
comm_rank: int = MPI_comm.Get_rank()
## Write comm info to file
file_name: str = "rank_{}.txt".format(comm_rank)
file_path: str = os.path.join(tmp_path, file_name)
with open(file_path, "w") as file:
file.write("{}".format(comm_rank))
Код: Выделить всё
mpirun -n 4 python -m pytest --with-mpi --basetemp=out -v -k test_mpi
Код: Выделить всё
=============================================== ERRORS ===============================================
_____________________________________ ERROR at setup of test_mpi _____________________________________
self = PosixPath('/xxx/out')
mode = 448, parents = False, exist_ok = False
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
"""
Create a new directory at this given path.
"""
try:
> os.mkdir(self, mode)
E FileExistsError: [Errno 17] File exists: '/xxx/out'
/home/usr/miniconda3/envs/hpc/lib/python3.12/pathlib.py:1311: FileExistsError
Что я пробовал :
- В readthedocs pytest-mpi упоминаются некоторые «фикстуры», связанные с temp_path . Честно говоря, я не совсем понимаю, что такое фикстуры и как их использовать, но выглядит многообещающе!
Есть еще один код На Github есть блок кода, который, кажется, решает эту проблему, но он не работал последовательно для трех процессов и вообще не работал более чем с двумя процессами.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ith-pytest