I’m building a project in python with the Orekit python wrapper, and want to use pytest for unit testing. When setting up fixtures that initialize the orekit/java vm, pytest fails reporting an “access violation” (on windows). Has anyone had success with using pytest in a project that includes Orekit?
The test fixture code is:
from arcsim.models import Scenario
def new_scenario():
sce = Scenario("Test Scenario")
return sce
The unit test code is:
class TestScenario:
def test_repr(self, new_scenario):
out = new_scenario.__repr__()
assert "arcsim.models.Scenario object" in out
And the resulting pytest output is:
(arcsim) G:\My Drive\Satellite Architecture\Python\ArcSim>pytest -v
========================== test session starts ======================
platform win32 -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
cachedir: .pytest_cache
rootdir: G:\My Drive\Satellite Architecture\Python\ArcSim
plugins: cov-2.10.0
collected 1 item
test/test_models.py::TestScenario::test_repr Windows fatal exception: access violation
Current thread 0x00002e10 (most recent call first):
File "G:\My Drive\Satellite Architecture\Python\ArcSim\arcsim\models.py", line 55 in __init__
File "G:\My Drive\Satellite Architecture\Python\ArcSim\test\conftest.py", line 55 in new_scenario
File "C:\Users\EmRa\.conda\envs\arcsim\lib\site-packages\_pytest\fixtures.py", line 792 in call_fixture_func
[ ... and so on ... ]
Line 55 in the models.py file is the first time an Orekit function is called to build the Earth model. The source is below (I took out comment lines to make it shorter):
# orekit init
import orekit
from orekit.pyhelpers import setup_orekit_curdir
vm = orekit.initVM()
setup_orekit_curdir('data/orekit-data.zip')
# space dynamics libraries
# https://www.orekit.org/site-orekit-development/apidocs/index.html
from org.orekit.frames import FramesFactory, TopocentricFrame
from org.orekit.utils import Constants, IERSConventions
from org.orekit.time import TimeScalesFactory, AbsoluteDate
from org.orekit.bodies import OneAxisEllipsoid, GeodeticPoint
class Scenario():
def __init__(self, name):
self.name = name
ITRF = FramesFactory.getITRF(IERSConventions.IERS_2010, True)
self.Earth = OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
Constants.WGS84_EARTH_FLATTENING, ITRF)
Is there a way to use calls to the orekit vm in pytest without causing access violations? Thanks!