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.

AttributeError: module 'pytest' has no attribute 'lazy_fixture'

See original GitHub issue

I have installed pytest-lazy-fixture:

pip install pytest-lazy-fixture
Collecting pytest-lazy-fixture
  Downloading pytest-lazy-fixture-0.4.0.tar.gz
Collecting pytest>=2.9.2 (from pytest-lazy-fixture)
  Downloading pytest-3.4.0-py2.py3-none-any.whl (188kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 194kB 645kB/s 
Requirement already satisfied: setuptools in /home/overflow012/.virtualenvs/split_dataset/lib/python3.5/site-packages (from pytest>=2.9.2->pytest-lazy-fixture)
Collecting py>=1.5.0 (from pytest>=2.9.2->pytest-lazy-fixture)
  Downloading py-1.5.2-py2.py3-none-any.whl (88kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 92kB 1.0MB/s 
Collecting pluggy<0.7,>=0.5 (from pytest>=2.9.2->pytest-lazy-fixture)
  Downloading pluggy-0.6.0.tar.gz
Requirement already satisfied: six>=1.10.0 in /home/overflow012/.virtualenvs/split_dataset/lib/python3.5/site-packages (from pytest>=2.9.2->pytest-lazy-fixture)
Collecting attrs>=17.2.0 (from pytest>=2.9.2->pytest-lazy-fixture)
  Downloading attrs-17.4.0-py2.py3-none-any.whl
Building wheels for collected packages: pytest-lazy-fixture, pluggy
  Running setup.py bdist_wheel for pytest-lazy-fixture ... done
  Stored in directory: /home/overflow012/.cache/pip/wheels/85/9e/a0/45b3bca5fb2b27171cf4537a2b77a078db0140789c364431e3
  Running setup.py bdist_wheel for pluggy ... done
  Stored in directory: /home/overflow012/.cache/pip/wheels/df/44/8e/e136760ae525eac46b3e3db643ef58ff1753177b5a722b0c96
Successfully built pytest-lazy-fixture pluggy
Installing collected packages: py, pluggy, attrs, pytest, pytest-lazy-fixture
Successfully installed attrs-17.4.0 pluggy-0.6.0 py-1.5.2 pytest-3.4.0 pytest-lazy-fixture-0.4.0

When I run pytest I get error:

____________________________________________________ ERROR collecting test/test_split_dataset.py _____________________________________________________
test/test_split_dataset.py:28: in <module>
    "source": pytest.lazy_fixture("dataset_path")
E   AttributeError: module 'pytest' has no attribute 'lazy_fixture'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================== 1 error in 1.20 seconds ===============================================================

Tests:

@pytest.fixture(scope="module", autouse=True)
def dataset_path(tmpdir_factory):
    p = tmpdir_factory.mktemp("tmp").join("dataset.csv")
    df = pd.DataFrame({
        "a": [1, 2, 3, 4, 5, 6],
        "b": [1, 2, 3, 4, 5, 6],
        "c": [1, 2, 3, 4, 5, 6],
        "d": [1, 2, 3, 4, 5, 6],
    })
    df.to_csv(p, index=False)

    yield str(p)  # all code below it will be executed when session done
    os.remove(str(p))


@pytest.mark.parametrize("test_input,expected", [
    ({
        "input": {
            "format": "csv",
            "source": pytest.lazy_fixture("dataset_path")
        },
        "split": {
            "targets": "c",
            "seeds": [1, 5, 34],
            "params":{
                "train_size": 0.7,
                "random_state": 42
            }
        }
    }, 8)
])
def test_dataset(test_input, expected):
    print(test_input)
    assert False

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
TvoroGcommented, Jan 31, 2018

Hi! Thanks for notifying. I think it should be because of this https://github.com/TvoroG/pytest-lazy-fixture/issues/16. Try to import lazy_fixture:

from pytest_lazyfixture import lazy_fixture

and use it instead of pytest.lazy_fixture.

0reactions
CristhianBoujoncommented, Feb 1, 2018

Yes, it is possible, I actually do that but I think this is an issue, anyway

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest can't find pytest.fixture_request - Stack Overflow
As a workaround, you can use the package pytest-lazy-fixture (can be installed with pip ): instead of pytest.fixture_request('fixture_name')Β ...
Read more >
pytest-lazy-fixture - PyPI
It helps to use fixtures in pytest.mark.parametrize. ... pytest-lazy-fixture 0.6.3. pip install pytest-lazy-fixture ... Tests can be run with tox.
Read more >
Getting AttributeError: module 'pytest' has no attribute 'main ...
The test runner is py.test while running the test. 2. The location of the driver is properly given. 3. The package name and...
Read more >
"AttributeError: module 'pytest' has no attribute 'hookimpl ...
"AttributeError: module 'pytest' has no attribute 'hookimpl'" running tests in PyCharm. Open two Python projects in the same PyCharm window.
Read more >
Welcome to pytest-factoryboy's documentation! β€” pytest ...
pytest -factoryboy makes it easy to combine factory approach to the test setup with ... Attribute names are prefixed with the model fixture...
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