Skip to content

Conversation

@Karrenbelt
Copy link
Collaborator

@Karrenbelt Karrenbelt commented Apr 14, 2025

  • Patched PYTHONPATH in test_filesystem fixtures to improve test isolation
  • Added pytest-xdist support in pyproject.toml for parallel test execution
  • Added hypothesis.settings for scaffolded protocols
  • Updated pyproject.toml to include additional tool.coverage settings for isolated filesystem paths
  • Implemented get_test_cpu_count in auto_dev/tests based on os.environ.get('CI')
  • Disabled test_repo.py temporarily for stability. --> Re-enabled in Streamline repo scaffolding & re-write & re-enable repo scaffolding tests #639

Note: PR #639 re-enables test_repo.py

@Karrenbelt Karrenbelt changed the base branch from main to refactor/protocol_scaffolder April 14, 2025 20:30
Comment on lines +17 to +19
def get_test_cpu_count() -> str:
"""Determine how many CPUs to use for pytest-xdist."""
return str(cpu_count()) if os.getenv("CI") else "auto"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on local this ensures not all cores will be used (3/4th I believe), while on the CI we take all that are available

Comment on lines +122 to +123
[tool.coverage.paths]
source = ["auto_dev", "/tmp/*/auto_dev"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this increased test coverage locally from ~34% to ~53%

We have some issue on CI generating the coverage report tho, it appears (see CI run)

1s
Run MishaKav/pytest-coverage-comment@main
File read successfully "/Users/runner/work/auto_dev/auto_dev/./coverage-report.txt"
Error: Coverage file "/Users/runner/work/auto_dev/auto_dev/./coverage-report.txt" has bad format or wrong data
./coverage-report.txt
Nothing to report

Comment on lines 14 to 19
HYPOTHESIS_SETTINGS = """
from hypothesis import HealthCheck, settings
settings.register_profile("generated", deadline=1000, suppress_health_check=[HealthCheck.too_slow])
settings.load_profile("generated")
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running with pytest-xdist, certain harmless issues incorrectly surface. To avoid modifying the scaffolded codebase in a way that affects production code, we inject a workaround into the generated tests/__init__.py during integration tests to ensure tests pass without impacting the production scaffold

Comment on lines 135 to 138
result = subprocess.run(command, env=env, check=False, text=True, capture_output=True)
result = subprocess.run(command, check=False, text=True, capture_output=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer needed now that monkeypatch.setenv is used in the fixtures

assert not error_messages


@pytest.mark.skip
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the ghosts of a flawed pattern I once endorsed. I’ve since repented; see #639

Base automatically changed from refactor/protocol_scaffolder to main April 29, 2025 15:39
make_commands = "fmt", "lint", "test"


@pytest.mark.skip
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why skip this entire set of tests?

Copy link
Collaborator Author

@Karrenbelt Karrenbelt May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was temporary, since these tests were very poorly written and caused interference with other tests. They have been re-enabled in PR #639, which was already merged into this PR, and this is their current state in this PR:

"""Tests for the click cli."""
import subprocess
from pathlib import Path
def _test_repo_scaffold(repo_type, make_commands, cli_runner, test_clean_filesystem):
repo_root = Path(test_clean_filesystem) / "dummy"
command = ["adev", "repo", "scaffold", repo_root.name, "-t", repo_type]
runner = cli_runner(command)
result = runner.execute()
makefile = repo_root / "Makefile"
# Verify the basic repository structure exists
assert result, runner.output
assert repo_root.exists(), f"Repository {repo_root} does not exist."
assert (repo_root / ".git").exists(), f".git directory not found in {repo_root}."
assert makefile.exists(), f"Makefile not found in {repo_root}."
# Run each make command and collect any errors.
error_messages = {}
for cmd in make_commands:
proc_result = subprocess.run(
["make", cmd],
shell=False,
capture_output=True,
text=True,
check=False,
cwd=repo_root,
)
if proc_result.returncode != 0:
error_messages[cmd] = proc_result.stderr
assert not error_messages, f"Errors encountered in make commands: {error_messages}"
def test_python_repo(cli_runner, test_clean_filesystem):
"""Test scaffolding a Python repository."""
_test_repo_scaffold(
repo_type="python",
make_commands=("fmt", "lint", "test"),
cli_runner=cli_runner,
test_clean_filesystem=test_clean_filesystem,
)
def test_autonomy_repo(cli_runner, test_clean_filesystem):
"""Test scaffolding an Autonomy repository."""
_test_repo_scaffold(
repo_type="autonomy",
make_commands=("fmt", "lint", "test", "hashes"),
cli_runner=cli_runner,
test_clean_filesystem=test_clean_filesystem,
)

8ball030 and others added 3 commits May 4, 2025 12:20
@8ball030 8ball030 merged commit dd9ace1 into main May 8, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants