pytest unit testing help

ChristianRRL
Honored Contributor II

Hi there, I am hoping someone can help me understand why I'm having issues with a simple pytest unit test... test?

When attempting to run a `run_tests_notebook` in our all-purpose compute cluster (Runtime 14.3) with the following:

import pytest
import os
import sys

# Run pytest.
retcode = pytest.main([".", "-v", "-p", "no:cacheprovider"])

# Fail the cell execution if there are any test failures.
assert retcode == 0, "The pytest invocation failed. See the log for details."

I get the following error message:

============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-9.0.2, pluggy-1.6.0 -- /local_disk0/.ephemeral_nfs/envs/pythonEnv-9d50e02c-01b0-47de-95e6-456ef5c86d1c/bin/python
rootdir: /Workspace/Users/username@company.com/sandbox/unit_test_sample
plugins: anyio-3.5.0
collecting ... collected 0 items / 1 error

==================================== ERRORS ====================================
____________________ ERROR collecting test_my_functions.py _____________________
ImportError while importing test module '/Workspace/Users/username@company.com/sandbox/unit_test_sample/test_my_functions.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'test_my_functions'
=========================== short test summary info ============================
ERROR test_my_functions.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.52s ===============================
AssertionError: The pytest invocation failed. See the log for details.

However, when I switch to the Serverless cluster and attempt to `Run tests` directly on my `test_my_functions.py` file (feature not available in Runtime 14.3), I am seeing that my unit tests are passing successfully: