Skip to content

Instantly share code, notes, and snippets.

@milliams
Created March 1, 2016 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milliams/43bb69cf7f18dc398526 to your computer and use it in GitHub Desktop.
Save milliams/43bb69cf7f18dc398526 to your computer and use it in GitHub Desktop.
Example pytest fixtures for little ganga
import pytest
from Ganga.GPIDev.Base.Proxy import stripProxy
@pytest.yield_fixture
def ganga():
"""
Provide the ganga GPI and runtime to the test
"""
import ganga
yield ganga
ganga.jobs.clean(confirm=True) # This could be anything but simple for now
@pytest.fixture
def monitor():
"""
A function to run a job to completion
"""
def monitor_job(j):
j = stripProxy(j)
b = type(j.backend)
while True:
print('j.status')
if j.status in ['completed', 'failed']:
return True
b.master_updateMonitoringInformation([j])
return monitor_job
def test_ganga(ganga, monitor):
"""
Test that we can submit and monitor jobs
"""
j = ganga.Job()
j.submit()
monitor(j)
assert j.status == 'completed'
def test_cleanup(ganga):
"""
Test that the jobs registry is cleaned
"""
assert len(ganga.jobs) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment