Skip to content

Add automated testing for Jupyter notebooks #220

@Artemon-line

Description

@Artemon-line

🚀 The feature, motivation and pitch

Overview

Automate testing for notebooks in examples/notebooks/ to ensure they remain executable and up-to-date.

Current Notebooks

  • Cybersecurity_demo.ipynb
  • LlamaGuard.ipynb
  • LlamaGuardMM.ipynb

Recommended Approach

Use nbmake for execution testing + testbook for detailed unit tests.

nbmake (execution testing)

pytest --nbmake examples/notebooks/*.ipynb                                                                                                                  

testbook (unit testing)

  @testbook('examples/notebooks/LlamaGuard.ipynb', execute=True)                                                                                              
  def test_llamaguard_notebook(tb):                                                                                                                           
      tb.execute_cell([0, 1, 2])                                                                                                                              
      assert tb.ref('some_variable') is not None                                                                                                              

Dependencies to Add

nbmake>=1.4.0
testbook>=0.4.2
jupyter>=1.0.0

Implementation Notes

  • Mock external API calls
  • Set appropriate cell timeouts
  • Create fixtures for common test data
  • Configure in pytest.ini

Success Criteria

  • Dependencies added
  • All notebooks execute successfully
  • Test configuration in pytest.ini
  • Mock fixtures for external dependencies
  • Documentation updated

Alternatives

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions