question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CLI] `ImportError: cannot import name '_get_mock_module' from 'pytest_mock'`

See original GitHub issue

Description The pytest test suite fails with

ImportError while loading conftest '/build/source/tests/conftest.py'.
tests/conftest.py:15: in <module>
    from tests import utils
tests/utils/__init__.py:7: in <module>
    from tests.utils.mock_backend import BackendMock
tests/utils/mock_backend.py:8: in <module>
    from pytest_mock import _get_mock_module  # type: ignore
E   ImportError: cannot import name '_get_mock_module' from 'pytest_mock' (/nix/store/cn86h8xap96v0xxfzypg5zr8xjbzccgm-python3.9-pytest-mock-3.6.1/lib/python3.9/site-packages/pytest_mock/__init__.py)

when using pytest-mock v3.6.1.

Wandb features n/a

How to reproduce Build this nix derivation:

source
{ buildPythonPackage
, flask
, pytest-mock
, click
, pytestCheckHook
, configparser
, docker_pycreds
, fetchFromGitHub
, matplotlib
, bokeh
, git
, GitPython
, lib
, pathtools
, promise
, protobuf
, psutil
, python
, python-dateutil
, pyyaml
, requests
, sentry-sdk
, shortuuid
, subprocess32 ? null
, yaspin
}:

buildPythonPackage rec {
  pname = "wandb";
  version = "0.12.2";

  src = fetchFromGitHub {
    owner = pname;
    repo = "client";
    rev = "v${version}";
    sha256 = "0rdh7vgb3njj9xi8kjfm4735zw3slzvc0qsvsc7nrl65d8iwn0j3";
  };

  # The wandb requirements.txt does not distinguish python2/3 dependencies. We
  # need to drop the subprocess32 dependency when building for python3.
  patchPhase = lib.optional python.isPy3 ''
    sed -i 's/^subprocess32>=.*//' requirements.txt
  '';

  # git is not a setup.py dependency of wandb, but wandb does expect git to be
  # in PATH.
  propagatedBuildInputs = [
    click
    configparser
    docker_pycreds
    git
    GitPython
    pathtools
    promise
    protobuf
    psutil
    python-dateutil
    pyyaml
    requests
    sentry-sdk
    shortuuid
    yaspin
  ] ++ lib.optionals python.isPy2 [ subprocess32 ];

  # The wandb tests require network access, and so cannot be run in the nix
  # build environment.
  # doCheck = false;
  checkInputs = [
    pytestCheckHook
    bokeh
    flask
    pytest-mock
    matplotlib
  ];

  pythonImportsCheck = [ "wandb" ];

  meta = with lib; {
    description = "A CLI and library for interacting with the Weights and Biases API";
    homepage = "https://github.com/wandb/client";
    license = licenses.mit;
    maintainers = with maintainers; [ samuela ];
  };
}

Environment

  • OS: NixOS
  • Environment: n/a
  • Python Version: 3.9

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vanpeltcommented, Oct 10, 2021

0.12.4 was a patch release. The next release will be early-mid next week and will contain the fix.

1reaction
vanpeltcommented, Oct 5, 2021

@samuela apologies, this didn’t make it into the last release. It will make it into the next one. Until then you can install from the branch as mentioned above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[CLI] ImportError: cannot import name '_get_mock_module ...
when using pytest-mock v3.6.1. Wandb features n/a. How to reproduce. Build this nix derivation: source.
Read more >
What can I do about "ImportError: Cannot import name X" or ...
You have circular dependent imports. physics.py is imported from entity before class Ent is defined and physics tries to import entity that is...
Read more >
pytest-mock - PyPI
This plugin provides a mocker fixture which is a thin-wrapper around the patching API provided by the mock package: import os class UnixFS:...
Read more >
How to Fix : “ImportError: Cannot import name X” in Python?
You can solve the “ ImportError : Cannot import name X” Error by resolving the circular dependencies. You can do that either by...
Read more >
[SOLVED] ImportError: cannot import name 'main' - YouTube
[SOLVED] [FIXED] ImportError : cannot import name 'main' appears when trying to install pipenv through python3 pip command!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found