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.

pip install'ed mock should not depend on command-line tools

See original GitHub issue

I’ve installed nose and mock into a chroot with some custom code and libraries.

i got following error when running nose:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/py_pkg/custom_src/test/test_something_custom.py", line 20, in <module>
    from mock import patch
  File "/usr/local/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "/usr/local/lib/python2.7/site-packages/mock/mock.py", line 71, in <module>
    _v = VersionInfo('mock').semantic_version()
  File "/usr/local/lib/python2.7/site-packages/pbr/version.py", line 452, in semantic_version
    self._semantic = self._get_version_from_pkg_resources()
  File "/usr/local/lib/python2.7/site-packages/pbr/version.py", line 439, in _get_version_from_pkg_resources
    result_string = packaging.get_version(self.package)
  File "/usr/local/lib/python2.7/site-packages/pbr/packaging.py", line 640, in get_version
    raise Exception("Versioning for this project requires either an sdist"
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed?

It appears that mock brought in pbr dependency and that wants to examine something at runtime.

Perhaps a packaging kludge is needed (sdist in the error).

Or just remove it entirely when installing a fixed version from pypi.

Python-2.7.10 nose=1.3.7 mock install: Successfully installed funcsigs-0.4 mock-1.3.0 pbr-1.4.0

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
OpaVotecommented, Oct 11, 2015

This fixed it for me: pip install --upgrade setuptools

4reactions
Andrusocommented, Oct 10, 2016

This still seems to be an issue and a pretty annoying one as it takes down the whole test-runner.

File "/Users/blah/blah.py", line 11, in <module>
    import mock
  File "/Library/Python/2.7/site-packages/mock/__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "/Library/Python/2.7/site-packages/mock/mock.py", line 71, in <module>
    _v = VersionInfo('mock').semantic_version()
  File "/Library/Python/2.7/site-packages/pbr/version.py", line 460, in semantic_version
    self._semantic = self._get_version_from_pkg_resources()
  File "/Library/Python/2.7/site-packages/pbr/version.py", line 447, in _get_version_from_pkg_resources
    result_string = packaging.get_version(self.package)
  File "/Library/Python/2.7/site-packages/pbr/packaging.py", line 725, in get_version
    raise Exception("Versioning for this project requires either an sdist"
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed?

Python 2.7.12 mock (2.0.0) setuptools (28.3.0) pbr (1.10.0) pip (8.1.2)

By now, it seems that PBR is slowly dying https://bugs.launchpad.net/pbr

Is it perhaps time to remove dependency on command-line tools as OP suggested?

I simply tried commenting out references to VersionInfo, version and version_info and the tests ran fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cli-mock - PyPI
This package provides two command line utilities: crecord and creplay. The former records the output (stdout and stderr) and the return code of...
Read more >
Python/tox Install a dependency as editable - Stack Overflow
This example tells tox to install mock and pytest in to each virtualenv before running the tests. Tox will use pip to install...
Read more >
Using Mock to test package builds - Fedora Project Wiki
This ensures that your BuildRequires lines are correct, that there are no missing dependencies, and that it builds cleanly. The Mock user ...
Read more >
Understanding the Python Mock Object Library - Real Python
In this tutorial, you'll learn how to use the Python mock object library, unittest.mock, to create and use mock objects to improve your...
Read more >
Announcing Poetry 1.2.0 | Blog
Poetry will be installed using the Python interpreter the installer ... [tool.poetry.dev-dependencies] pytest = "^7.1.0" pytest-mock = "*".
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