conftest.py 628 B

1234567891011121314151617181920
  1. import pytest
  2. from pathlib import Path
  3. import os, sys
  4. # add helpers to path
  5. sys.path.append(os.path.join(os.path.dirname(__file__), 'helpers'))
  6. def copy_file_to_tmpdir(tmpdir, source_file, target_path=None):
  7. "Utility to copy file from test_files to temporary directory"
  8. source_path = Path(os.path.dirname(__file__)) / "test_files" / source_file
  9. fh = tmpdir.join(Path(target_path).name if target_path is not None else source_path.name)
  10. with open(source_path) as f:
  11. fh.write(f.read())
  12. return fh
  13. @pytest.fixture
  14. def dummy_png(tmpdir):
  15. return copy_file_to_tmpdir(tmpdir, source_file="dummy.png")