python-tests

par nvidia

Tests Python pour NeMo Fabric; utilisez ceci lors de l'écriture de tests

npx skills add https://github.com/nvidia/nemo-fabric --skill python-tests

Python Test Style

  • Pytest is used to run tests.
  • Do not add @pytest.mark.asyncio to any test. Async tests are automatically detected and run by the async runner; the decorator is unnecessary clutter.
  • Do not add a -> None return type annotation to test functions. This is not a common convention in pytest and adds unnecessary verbosity.
  • When mocking a class, do not define a new class. Use unittest.mock.MagicMock or unittest.mock.AsyncMock, with the spec constructor argument when necessary.
  • The name of the mocked class should be prefixed with mock, not fake.
  • Prefer pytest fixtures over helper methods.
  • Do not repeat fixtures, if a fixture is needed in multiple test files, place it in a conftest.py file.
  • When creating a fixture follow this pattern:
    @pytest.fixture(name="<fixture_name>"[, scope="<scope>"])
    def <fixture_name>_fixture() -> <return_type>:
        ...
    
    Only specify the scope argument when the value is something other than "function".
  • Prefer pytest.mark.parametrize over creating individual tests for different input types.
  • If a fixture is needed for a test, but either does not return a value or the value is not used in the test, use the @pytest.mark.usefixtures decorator.
  • tests/conftest.py contains a restore_environ_fixture fixture that restores the environment variables to their original state after each test, it is defined with autouse=True so it is automatically applied to all tests. If you need to modify the environment variables in a test, do so using os.environ and the fixture will restore them after the test completes. There is no need to use monkeypatch.setenv to modify environment variables in tests.
  • Avoid defensive programming in tests. If a test fails, it should fail loudly and clearly, rather than silently passing due to defensive checks. For example
    data = results["data"]
    
    is preferred over
    data = results.get("data")
    
    Simply allow the resulting KeyError to be raised if the "data" key is not present in the results dictionary, as this will provide a clear indication of what went wrong in the test.

Common Commands

# Focused test loop
uv run pytest -k "<pattern>"

# Run all tests
uv run pytest

Do Not Write Tests For

  • Documentation.
  • Test helper code under tests/_utils/.
  • Package metadata or wheel installation behavior.

References

  • pyproject.toml
  • tests/conftest.py

Plus de skills de nvidia

compileiq-debug
nvidia
Utilisez quand quelque chose ne va pas : Search() bloque, toutes les évaluations retournent INVALID_SCORE, les scores ne s'améliorent pas, chaque configuration retourne le même nombre, erreurs ptxas…
create-github-pr
nvidia
Créer des pull requests GitHub en utilisant l'interface en ligne de commande gh. Utiliser lorsque l'utilisateur souhaite créer une nouvelle PR, soumettre du code pour révision, ou ouvrir une pull request. Mots-clés de déclenchement -…
nemoclaw-maintainer-cross-issue-sweep
nvidia
Analyse les autres problèmes ouverts pour trouver ceux qu’une PR donnée pourrait également corriger ou casser accidentellement. Génère des opportunités de correctifs adjacents et des risques de contradiction avec fichier:ligne…
fhir-basics
nvidia
Apprend aux agents comment fonctionnent les API FHIR R4, quelles ressources sont disponibles, comment les interroger avec des paramètres de recherche, et comment analyser correctement tous les formats de réponse…
compileiq-validate-result
nvidia
Utiliser APRÈS qu'une recherche soit terminée et AVANT de réclamer un accélérateur ou d'expédier un ACF. Charge le CSV dump_results, extrait les K meilleurs candidats (mono-objectif)…
changelog-audit
nvidia
Auditer le CHANGELOG.md de Warp avant une publication : récupérer les entrées perdues, trier par impact utilisateur, affiner le langage des entrées, ajuster les retours à la ligne et (en mode branche de publication) mettre à jour la comparaison…
maintain-dynamic-plugins
nvidia
Maintenir les chargeurs de plugins dynamiques NeMo Relay, les manifestes, les SDK natifs Rust, le protocole worker gRPC, le SDK worker Python, la documentation, les tests et la couverture du workflow de publication
dgx-diagnose
nvidia
Diagnostiquer les problèmes courants du DGX Station GB300 — plantages CUDA, ciblage incorrect du GPU, bugs de conteneur vLLM/SGLang, problèmes d'état MIG, erreurs NVLink/Fabric Manager,…