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.

Missing fixture when using distributed.utils_test.client fixture in pytest

See original GitHub issue

What happened:

When attempting to use the distributed.utils_test.client in a test suite for one of my packages, my tests error out due to a missing fixture loop that is required by the client fixture. The traceback is pasted below in the MCVE.

What you expected to happen:

To be able to use the client fixture without raising an error when running tests that require a distributed.Client instance.

Minimal Complete Verifiable Example:

from distributed.utils_test import client


def test_foo(client):
    def inc(x):
        return x + 1
    foo = client.submit(inc, x)

when running this as,

pytest test-dask-client-fixture.py (where I’ve put the above snippet in a file called dask-client-fixture.py), I get the following error message from pytest,

======================================================= test session starts ========================================================
platform darwin -- Python 3.8.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /Users/wbarnes/Desktop
collected 1 item

test-dask-client.py E                                                                                                        [100%]

============================================================== ERRORS ==============================================================
____________________________________________________ ERROR at setup of test_foo ____________________________________________________
file /Users/wbarnes/Desktop/test-dask-client.py, line 4
  def test_foo(client):
file /Users/wbarnes/miniconda3/envs/dask-fresh/lib/python3.8/site-packages/distributed/utils_test.py, line 543
  @pytest.fixture
  def client(loop, cluster_fixture):
E       fixture 'loop' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, client, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/Users/wbarnes/miniconda3/envs/dask-fresh/lib/python3.8/site-packages/distributed/utils_test.py:543
===================================================== short test summary info ======================================================
ERROR test-dask-client.py::test_foo
========================================================= 1 error in 5.25s =========================================================

Environment:

  • Dask version: 2021.1.1
  • Python version: 3.8.5
  • pytest version: 6.2.2
  • Operating System: macOS 10.15.3 (I’ve also encountered this on Ubuntu 18.04.5)
  • Install method (conda, pip, source): pip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jrbourbeaucommented, Feb 3, 2021

Hmm in that case, you might be best off creating your own fixture where you set the scope= keyword in pytest.fixture. For example, something along the lines of (haven’t tested the snippet below at all):

from distributed import LocalCluster

@pytest.fixture(scope="session")
def test_cluster():
    with LocalCluster() as cluster:
        yield cluster
0reactions
jrbourbeaucommented, Feb 3, 2021

Sounds good. Good luck @wtbarnes!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use fixtures — pytest documentation
Once pytest finds them, it runs those fixtures, captures what they returned (if anything), and passes those objects into the test function as...
Read more >
pytest fixture of fixture, not found - Stack Overflow
Yes, it is possible. If you have the test and all the fixtures in 1 file: test.py import pytest @pytest.fixture def foo(): return...
Read more >
End-To-End Tutorial For Pytest Fixtures With Examples
Fixtures are a set of resources that have to be set up before and cleaned up once the Selenium test automation execution is...
Read more >
pytest-steps
fixture decorators, so that you can create incremental tests with steps without having to think about the pytest fixture/parametrize pattern that has to...
Read more >
All You Need To Know To Start Using Fixtures In Your Pytest ...
The @pytest.fixture decorator provides an easy yet powerful way to setup and teardown resources. You can then pass these defined fixture objects ...
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