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.

3.7.0: pytest is failing in `tests/test_pytest_mock.py::test_standalone_mock` unit

See original GitHub issue

I’m trying to package your module as an rpm package. So I’m using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I’m calling build with --no-isolation I’m using during all processes only locally installed modules
  • install .whl file in </install/prefix>
  • run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.7.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.7.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -p no:relaxed
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/pytest-mock-3.7.0, configfile: tox.ini
plugins: mock-3.7.0, cov-3.0.0, asyncio-0.17.2
asyncio: mode=auto
collected 72 items

tests/test_pytest_mock.py .........................................................F..............                                                                   [100%]

================================================================================= FAILURES =================================================================================
___________________________________________________________________________ test_standalone_mock ___________________________________________________________________________

testdir = <Testdir local('/tmp/pytest-of-tkloczko/pytest-2/test_standalone_mock0')>

    def test_standalone_mock(testdir: Any) -> None:
        """Check that the "mock_use_standalone" is being used."""
        testdir.makepyfile(
            """
            def test_foo(mocker):
                pass
        """
        )
        testdir.makeini(
            """
            [pytest]
            mock_use_standalone_module = true
        """
        )
        result = testdir.runpytest_subprocess()
>       assert result.ret == 3
E       assert <ExitCode.OK: 0> == 3
E        +  where <ExitCode.OK: 0> = <RunResult ret=ExitCode.OK len(stdout.lines)=20 len(stderr.lines)=0 duration=0.46s>.ret

/home/tkloczko/rpmbuild/BUILD/pytest-mock-3.7.0/tests/test_pytest_mock.py:723: AssertionError
--------------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------------
running: /usr/bin/python3 -mpytest --basetemp=/tmp/pytest-of-tkloczko/pytest-2/test_standalone_mock0/runpytest-0
     in: /tmp/pytest-of-tkloczko/pytest-2/test_standalone_mock0
============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /tmp/pytest-of-tkloczko/pytest-2/test_standalone_mock0, configfile: tox.ini
plugins: mock-3.7.0, cov-3.0.0, asyncio-0.17.2
asyncio: mode=legacy
collected 1 item

test_standalone_mock.py .                                                [100%]

=============================== warnings summary ===============================
../../../../usr/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191
  /usr/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

test_standalone_mock.py::test_foo
  /usr/lib/python3.8/site-packages/pytest_asyncio/plugin.py:317: DeprecationWarning: '@pytest.fixture' is applied to <fixture _mocker, file=/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.7.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py, line=388> in 'legacy' mode, please replace it with '@pytest_asyncio.fixture' as a preparation for switching to 'strict' mode (or use 'auto' mode to seamlessly handle all these fixtures as asyncio-driven).
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================== 1 passed, 2 warnings in 0.03s =========================
========================================================================= short test summary info ==========================================================================
FAILED tests/test_pytest_mock.py::test_standalone_mock - assert <ExitCode.OK: 0> == 3
======================================================================= 1 failed, 71 passed in 6.16s =======================================================================
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:80: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-6f5bceaa-27c1-4828-a3c4-0d1d4c62f501
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-tkloczko/garbage-6f5bceaa-27c1-4828-a3c4-0d1d4c62f501'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:80: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-f0b2eb80-1df2-41e3-b9c6-7ae4bdb46198
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-tkloczko/garbage-f0b2eb80-1df2-41e3-b9c6-7ae4bdb46198'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:80: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-aa20aba2-7e0e-4ebb-8719-a5e007e0d1c4
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-tkloczko/garbage-aa20aba2-7e0e-4ebb-8719-a5e007e0d1c4'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:80: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-d429fee2-5f3d-428e-92a2-6e0fc3e29972
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-tkloczko/garbage-d429fee2-5f3d-428e-92a2-6e0fc3e29972'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:80: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-0e7d96b3-02dc-4fec-88d8-b31f111ddb5d
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-tkloczko/garbage-0e7d96b3-02dc-4fec-88d8-b31f111ddb5d'
  warnings.warn(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:80: PytestWarning: (rm_rf) error removing /tmp/pytest-of-tkloczko/garbage-9f197e27-3fb6-4540-9abc-37cc28021b4e
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-tkloczko/garbage-9f197e27-3fb6-4540-9abc-37cc28021b4e'
  warnings.warn(

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nicoddemuscommented, Jun 24, 2022

@kloczek I usually avoid releasing versions without user-facing changes, that’s why this has been sitting for a while.

But we have #296 open, which certainly warrants a new release once merged. 👍

0reactions
kloczekcommented, Jun 24, 2022

Looks clean now. Thank you 👍

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.8.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.8.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/pytest-mock-3.8.1, configfile: tox.ini
plugins: mock-3.8.1, asyncio-0.18.2
asyncio: mode=auto
collected 73 items

tests/test_pytest_mock.py .........................................................................                                                                  [100%]

============================================================================ 73 passed in 3.92s ============================================================================
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle test failures — pytest documentation
This will invoke the Python debugger on every failure (or KeyboardInterrupt). Often you might only want to do this for the first failing...
Read more >
'pytest' exits with no error, but with "collected 0 items"
I wrote a unit test for this module (with a simple assert statement to check equality of lists) where I first instantiate the...
Read more >
3.3.1: pytest hangs in `tests/test_compat.py::TestMaybeAsync ...
Looks like pytest hangs in every other *[trio] unit :/ ... PASSED [ 7%] tests/test_debugging.py::test_main_task_name[trio] FAILED [ 7%] ...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
Note that in order to test something, we use one of the assert*() methods provided by the TestCase base class. If the test...
Read more >
Learn Pytest in 60 Minutes : Python Unit Testing Framework
py.test is an alternative, more Pythonic way of writing your tests. The pytest framework makes it easy to write small tests, yet scales...
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