Pytest is trying to access sensitive data/private path when running 'pytest --fixtures' on macOS
See original GitHub issue- a detailed description of the bug or suggestion
When trying to list the available built in fixture in pytest by simply running ‘pytest --fixtures’ an error is thrown as I did not give the permission to access my sensitive data.
Why pytest is trying to access my addressBook?
- output of
pip list
from the virtual environment you are using
=> pip list Package Version
atomicwrites 1.3.0
attrs 19.1.0
importlib-metadata 0.19
more-itertools 7.2.0
packaging 19.1
pip 19.2.3
pluggy 0.12.0
py 1.8.0
pyparsing 2.4.2
pytest 5.1.2
setuptools 41.2.0
six 1.12.0
wcwidth 0.1.7
wheel 0.33.6
zipp 0.6.0
- pytest and operating system versions
=> uname -a Darwin xxxx-MacBook-Pro.local 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
=> pytest --version This is pytest version 5.1.2, imported from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytest.py
- minimal example if possible
=> pytest --fixtures
=========================================================================================== test session starts ============================================================================================
platform darwin – Python 3.7.4, pytest-5.1.2, py-1.8.0, pluggy-0.12.0
rootdir: /Users/xxxx
collected 0 items / 1 errors
cache
Return a cache object that can persist state between testing sessions.
cache.get(key, default)
cache.set(key, value)
Keys must be a ``/`` separated value, where the first part is usually the
name of your plugin or application to avoid clashes with other cache users.
Values can be any object handled by the json stdlib module.
capsys
Enable text capturing of writes to sys.stdout
and sys.stderr
.
The captured output is made available via ``capsys.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``text`` objects.
capsysbinary
Enable bytes capturing of writes to sys.stdout
and sys.stderr
.
The captured output is made available via ``capsysbinary.readouterr()``
method calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``bytes`` objects.
capfd
Enable text capturing of writes to file descriptors 1
and 2
.
The captured output is made available via ``capfd.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``text`` objects.
capfdbinary
Enable bytes capturing of writes to file descriptors 1
and 2
.
The captured output is made available via ``capfd.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``byte`` objects.
doctest_namespace [session scope]
Fixture that returns a :py:class:dict
that will be injected into the namespace of doctests.
pytestconfig [session scope]
Session-scoped fixture that returns the :class:_pytest.config.Config
object.
Example::
def test_foo(pytestconfig):
if pytestconfig.getoption("verbose") > 0:
...
record_property
Add an extra properties the calling test.
User properties become part of the test report and are available to the
configured reporters, like JUnit XML.
The fixture is callable with (name, value)
, with value being automatically
xml-encoded.
Example::
def test_function(record_property):
record_property("example_key", 1)
record_xml_attribute
Add extra xml attributes to the tag for the calling test.
The fixture is callable with (name, value)
, with value being
automatically xml-encoded
record_testsuite_property [session scope]
Records a new <property>
tag as child of the root <testsuite>
. This is suitable to
writing global information regarding the entire test suite, and is compatible with xunit2
JUnit family.
This is a ``session``-scoped fixture which is called with ``(name, value)``. Example:
.. code-block:: python
def test_foo(record_testsuite_property):
record_testsuite_property("ARCH", "PPC")
record_testsuite_property("STORAGE_TYPE", "CEPH")
``name`` must be a string, ``value`` will be converted to a string and properly xml-escaped.
caplog Access and control log capturing.
Captured logs are available through the following properties/methods::
* caplog.text -> string containing formatted log output
* caplog.records -> list of logging.LogRecord instances
* caplog.record_tuples -> list of (logger_name, level, message) tuples
* caplog.clear() -> clear captured records and formatted log output string
monkeypatch
The returned monkeypatch
fixture provides these
helper methods to modify objects, dictionaries or os.environ::
monkeypatch.setattr(obj, name, value, raising=True)
monkeypatch.delattr(obj, name, raising=True)
monkeypatch.setitem(mapping, name, value)
monkeypatch.delitem(obj, name, raising=True)
monkeypatch.setenv(name, value, prepend=False)
monkeypatch.delenv(name, raising=True)
monkeypatch.syspath_prepend(path)
monkeypatch.chdir(path)
All modifications will be undone after the requesting
test function or fixture has finished. The ``raising``
parameter determines if a KeyError or AttributeError
will be raised if the set/deletion operation has no target.
recwarn
Return a :class:WarningsRecorder
instance that records all warnings emitted by test functions.
See http://docs.python.org/library/warnings.html for information
on warning categories.
tmpdir_factory [session scope]
Return a :class:_pytest.tmpdir.TempdirFactory
instance for the test session.
tmp_path_factory [session scope]
Return a :class:_pytest.tmpdir.TempPathFactory
instance for the test session.
tmpdir
Return a temporary directory path object
which is unique to each test function invocation,
created as a sub directory of the base temporary
directory. The returned object is a py.path.local
_
path object.
.. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html
tmp_path
Return a temporary directory path object
which is unique to each test function invocation,
created as a sub directory of the base temporary
directory. The returned object is a :class:pathlib.Path
object.
.. note::
in python < 3.6 this is a pathlib2.Path
================================================================================================== ERRORS ================================================================================================== ______________________________________________________________________________________ ERROR collecting test session _______________________________________________________________________________________ /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_error.py:66: in checked_call return func(*args, **kwargs) E PermissionError: [Errno 1] Operation not permitted: ‘/Users/xxxx/Library/Application Support/AddressBook’
During handling of the above exception, another exception occurred: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_path/common.py:377: in visit for x in Visitor(fil, rec, ignore, bf, sort).gen(self): /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_path/common.py:429: in gen for p in self.gen(subdir): /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_path/common.py:429: in gen for p in self.gen(subdir): /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_path/common.py:429: in gen for p in self.gen(subdir): /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_path/common.py:414: in gen entries = path.listdir() /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_path/local.py:392: in listdir names = py.error.checked_call(os.listdir, self.strpath) /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/_error.py:86: in checked_call raise cls(“%s%r” % (func.name, args)) E py.error.EPERM: [Operation not permitted]: listdir(‘/Users/xxxx/Library/Application Support/AddressBook’,) ============================================================================================= 1 error in 0.14s =============================================================================================
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
I don’t agree with you – garbage in garbage out essentially. There’s no reason to ever run
pytest
from/
or from~
.Here’s a much simpler reproduction:
Should this be an error? absolutely
@asottile @nicoddemus Thanks for clarifying this.