Run PyTorch tests on local build, Mac, M1 Apple Silicon

Hello,

I’m trying to run tests from the pytorch/test directory on Mac with M1 Apple Silicon.

The build was successful.

Python 3.12.10, Apple CLang version 17.0.0 (clang-1700.4.4.1)

python -m pip install --no-build-isolation -v -e .

I use VS Code to browse all the tests in the corresponding directory.

The first fix was in conftest.py because VS Code could not find pytest_shard_custom package.

# from pytest_shard_custom import pytest_addoptions as shard_addoptions, PytestShardPlugin
from .pytest_shard_custom import pytest_addoptions as shard_addoptions, PytestShardPlugin

During the directory scan, it now shows me the following error for all tests

ImportError: dlopen(/Users/user1/Documents/GitHub/pytorch/torch/_C.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_PyDict_GetItemRef'

It would be great if you could help me.

I’m not using VSCode myself so I can’t talk too much about the test discovery.

But we run test in a very particular way, you can check python test/run_test.py –help for details. And I am not surprised that VSCode doesn’t pick up on it.

ImportError: dlopen(/Users/user1/Documents/GitHub/pytorch/torch/_C.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_PyDict_GetItemRef'

This error looks like a python version mismatch. Make sure that you build and run with the same python version.

1 Like

Yep. There was a mistake in env configuration. Now it works. Thank you for helping.