writing-unit-tests

Guide creation and debugging of SCT framework unit tests with pytest conventions.

73|112|Updated Dec 29, 2015
One-click install
npx skills add https://github.com/scylladb/scylla-cluster-tests --skill writing-unit-tests-scylladb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-unit-tests
Source: https://github.com/scylladb/scylla-cluster-tests/tree/main/skills/writing-unit-tests
Command: npx skills add https://github.com/scylladb/scylla-cluster-tests --skill writing-unit-tests-scylladb

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on writing effective unit tests for the SCT framework, ensuring code quality and maintainability by adhering to best practices and avoiding common pitfalls.

Core Features & Use Cases

  • Test Writing Guidance: Learn pytest conventions, mocking strategies, and fixture usage.
  • Mocking External Services: Master techniques for isolating tests from AWS, GCE, Docker, and network calls using unittest.mock, moto, and monkeypatch.
  • Debugging Strategies: Understand how to troubleshoot slow, flaky, or failing unit tests.
  • Use Case: When developing a new feature in SCT, use this Skill to learn how to write isolated unit tests that verify your code's logic without relying on external infrastructure.

Quick Start

Consult the "Quick Reference: Test Infrastructure" section to understand available fixtures and markers for your tests.

Frequently Asked Questions about writing-unit-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for SCT without relying on external services?

To write unit tests for SCT without external services, isolate your code by mocking AWS, GCE, and network calls using unittest.mock, moto, and monkeypatch. This ensures tests verify logic independently without hitting live infrastructure.

What is the best way to mock AWS and GCE calls in pytest?

The best way to mock AWS and GCE calls in pytest is by using moto for AWS services and unittest.mock for GCE. These tools allow you to patch external interactions, ensuring your unit tests remain isolated and repeatable.

How do I debug slow or flaky pytest test runs?

Debug slow or flaky pytest runs by leveraging targeted debugging strategies and pytest fixtures. Isolate external dependencies with mocking to prevent network timeouts and identify non-deterministic behaviors causing test instability.

Can I use monkeypatch and unittest.mock together in SCT testing?

Yes, you can use monkeypatch and unittest.mock together in SCT testing. Monkeypatch handles safe attribute patching during test execution, while unittest.mock provides robust mock objects for verifying complex interactions.

What pytest fixtures are available for SCT unit tests?

Available pytest fixtures for SCT unit tests provide setup and teardown mechanisms for your test environment. Consult the test infrastructure reference to understand specific markers and fixtures designed to isolate test logic.

Why do my SCT unit tests fail when network calls are not mocked?

SCT unit tests fail without mocked network calls because they attempt to reach live external infrastructure. Isolating tests using monkeypatch or unittest.mock prevents these failures by ensuring no real network requests are executed.