Skip to content

Commit

Permalink
try mocker
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Jul 9, 2024
1 parent 072b2e1 commit c9bf659
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
21 changes: 19 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pylint = {version = "^2.12.2", optional = true}
coveralls = {version = "^3.3.1", optional = true}
pytest-qt = {version = ">=4.3.0", optional = true}
pynwb = {version="^2.0.0,!=2.5.1", optional= true}
pytest-mock = {version = "^3.14.0", optional = true}

[tool.poetry.dev-dependencies]
sphinx-autobuild = "^2021.3.14"
Expand All @@ -79,7 +80,10 @@ terminal = ["pyqtgraph", "PySide6"]
docs = ["Sphinx", "autodocsumm", "matplotlib", "sphinxcontrib-bibtex",
"scikit-learn", "altair", "bokeh", "colorcet", "sphinx-rtd-theme", "sphinx-sass", "pytest", "rich",
"PySide6", "pyqtgraph", "autodoc_pydantic", "myst_parser", "pynwb"]
tests = ["pytest", "pytest-cov", "pylint", "coveralls", "pytest-qt", "pigpio", "PySide6", "pyqtgraph", "rich"]
tests = [
"pytest", "pytest-cov", "pylint", "coveralls", "pytest-qt", "pytest-mock",
"pigpio", "PySide6", "pyqtgraph", "rich"
]
plotting = ["altair", "bokeh", "colorcet"]
extra_interfaces = ["datajoint-babel", "pynwb"]

Expand Down
40 changes: 26 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import pytest
import os

@pytest.fixture(scope='session', autouse=True)
def monkeypatch_cpuinfo(monkeypatch):
# only patch on github actions
if "CI" not in os.environ or not os.environ["CI"] or "GITHUB_RUN_ID" not in os.environ:
return

def patched_cpuinfo() -> dict:
return {}

import cpuinfo
monkeypatch.setattr(cpuinfo, 'get_cpu_info', patched_cpuinfo)

import blosc2.core
monkeypatch.setattr(blosc2.core, 'get_cpu_info', patched_cpuinfo)
def on_gh_actions() -> bool:
return "CI" in os.environ or os.environ["CI"] or "GITHUB_RUN_ID" in os.environ

@pytest.fixture(autouse=True)
def monkeypatch_cpuinfo(mocker):
# only patch on github actions
# if not on_gh_actions():
# return

# def patched_cpuinfo() -> dict:
# return {}
#
# class PatchedModule():
# get_cpu_info = patched_cpuinfo
#
# import cpuinfo
# monkeypatch.setattr(cpuinfo, 'get_cpu_info', patched_cpuinfo)
#
# import blosc2.core
# monkeypatch.setattr(blosc2.core, 'get_cpu_info', patched_cpuinfo)
#
# import tables.leaf
# monkeypatch.setattr(tables.leaf, 'cpuinfo', PatchedModule)

mocker.patch('cpuinfo.get_cpu_info', return_value={})
mocker.patch('blosc2.core.get_cpu_info', return_value={})
mocker.patch('tables.leaf.cpuinfo.get_cpu_info', return_value={})



0 comments on commit c9bf659

Please sign in to comment.