diff --git a/Makefile b/Makefile index c147f4074..8035bb78c 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,41 @@ -dev: - python3 -m venv .venv ifeq ($(OS), Windows_NT) - .venv\Scripts\activate + VENV_BIN = .venv/Scripts else - . .venv/bin/activate + VENV_BIN = .venv/bin endif - pip install '.[dev]' + +dev: + python3 -m venv .venv + $(VENV_BIN)/pip install '.[dev]' install: - pip install . + $(VENV_BIN)/pip install . fmt: - black databricks tests - autoflake -ri databricks tests - isort databricks tests + $(VENV_BIN)/black databricks tests + $(VENV_BIN)/autoflake -ri databricks tests + $(VENV_BIN)/isort databricks tests fmte: - black examples - autoflake -ri examples - isort examples + $(VENV_BIN)/black examples + $(VENV_BIN)/autoflake -ri examples + $(VENV_BIN)/isort examples lint: - pycodestyle databricks - autoflake --check-diff --quiet --recursive databricks + $(VENV_BIN)/pycodestyle databricks + $(VENV_BIN)/autoflake --check-diff --quiet --recursive databricks test: - pytest -m 'not integration and not benchmark' --cov=databricks --cov-report html tests + $(VENV_BIN)/pytest -m 'not integration and not benchmark' --cov=databricks --cov-report html tests integration: - pytest -n auto -m 'integration and not benchmark' --reruns 2 --dist loadgroup --cov=databricks --cov-report html tests + $(VENV_BIN)/pytest -n auto -m 'integration and not benchmark' --reruns 2 --dist loadgroup --cov=databricks --cov-report html tests benchmark: - pytest -m 'benchmark' tests + $(VENV_BIN)/pytest -m 'benchmark' tests coverage: test open htmlcov/index.html clean: - rm -fr dist *.egg-info .pytest_cache build htmlcov + rm -fr dist *.egg-info .pytest_cache build htmlcov .venv diff --git a/tests/test_venv_usage.py b/tests/test_venv_usage.py new file mode 100644 index 000000000..6720d0b2f --- /dev/null +++ b/tests/test_venv_usage.py @@ -0,0 +1,26 @@ +"""Test to verify that tests are running from within the project's virtual environment. + +This test exists to catch Makefile issues where the venv is created but not actually used. +If this test fails in CI, it means `make test` is using system Python instead of .venv/bin/python. +""" + +import sys + + +def test_running_in_venv(): + """Verify pytest is running from the project's .venv, not system Python.""" + # Log the Python paths being used for visibility in CI output + print(f"\n=== Python Environment Info ===") + print(f"sys.executable: {sys.executable}") + print(f"sys.prefix: {sys.prefix}") + print(f"sys.base_prefix: {sys.base_prefix}") + print(f"================================\n") + + # sys.prefix points to the Python installation being used + # If we're in the venv, it should contain '.venv' + assert ".venv" in sys.prefix, ( + f"Tests are NOT running from the project venv!\n" + f"sys.prefix = {sys.prefix}\n" + f"sys.executable = {sys.executable}\n" + f"This likely means the Makefile is not correctly using the venv it creates." + )