Skip to content

Commit

Permalink
session pytest setup
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Borreguero <[email protected]>
  • Loading branch information
jmborr committed Feb 16, 2024
1 parent 4d39d5e commit a16e0cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
- name: Test with pytest
working-directory: ./reduction
run: |
echo datasearch.directories=/home/cloud/_work/LiquidsReflectometer/LiquidsReflectometer/reduction/tests/data/liquidsreflectometer-data/nexus/ >> ~/.mantid/Mantid.user.properties
cat ~/.mantid/Mantid.user.properties
git submodule add --force https://code.ornl.gov/sns-hfir-scse/infrastructure/test-data/liquidsreflectometer-data.git tests/data/liquidsreflectometer-data
git submodule update --init
python -m pytest --cov=. --cov-report=xml --cov-report=term test
Expand Down
20 changes: 20 additions & 0 deletions reduction/test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# standard imports
import logging
from pathlib import Path
import os

data_dir = Path(__file__).parent.parent / "data"


def pytest_sessionstart(session):
r"""invoked by pytest at the very beginning"""
logger = logging.getLogger()
# Insert data directory in Mantid config file
mantid_config_dir = Path(os.environ["HOME"]) / ".mantid"
os.makedirs(str(mantid_config_dir), exist_ok=True) # create directory if it doesn't exists
mantid_config_file = mantid_config_dir / "Mantid.user.properties"
write_mode = "a" if mantid_config_file.exists() else "w" # append or create-then-write
with open(mantid_config_file, write_mode) as file_handle:
data_path = data_dir / "liquidsreflectometer-data" / "nexus"
file_handle.write(f"datasearch.directories={str(data_path)}")
logger.info("Appending data directory to mantid config file")

0 comments on commit a16e0cd

Please sign in to comment.