Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 pytest fixture in thrown error while in the test file runs
While Testing a @pytest.fixture(scope="module")

When the fixture is included in the test file - tests/, test works fine

import json, pytest

def author_file_json(tmpdir_factory):
    python_author_data = {
        'Ned': {'City': 'Boston'},
        'Brian': {'City': 'Portland'},
        'Luciano': {'City': 'Sau Paulo'}

    file = tmpdir_factory.mktemp('data').join('author_file.json')

    with'w') as f:
        json.dump(python_author_data, f)
    return file

def test_brian_in_portland(author_file_json):
    with as f:
        authors = json.load(f)
    assert authors['Brian']['City'] == 'Portland'

If I add the fixture author_file_json to and run pytest --fixtures, it shows up in the trace

But now if I run pytest tests/, I get an error -
E fixture 'author_file_json' not found
How can I fix this ?
Got it. has to be at the root of the working directory

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  pydev error pydev debugger: warning: trying to add breakpoint to file that does not e kwhhst 8 392 Jun-15-2019, 02:52 PM
Last Post: kwhhst
  split and test tweet data Jmekubo 1 124 May-08-2019, 10:48 AM
Last Post: michalmonday
  charmap codec can't decode byte error with gzipped file in python bluethundr 2 189 Apr-30-2019, 12:26 PM
Last Post: bluethundr
  Openpyxl - while saving excel file getting error shubhamjainj 1 282 Apr-09-2019, 12:05 PM
Last Post: Larz60+
  Pytest with requests a21250450 3 233 Mar-21-2019, 03:24 PM
Last Post: buran
  Test Case Assertion Error moga2003 10 521 Mar-18-2019, 01:06 AM
Last Post: moga2003
  test pattern and add result in a table sam1975 1 184 Mar-05-2019, 02:41 PM
Last Post: sam1975
  Getting error while loading excel(.xlsx) file using openpyxl module shubhamjainj 1 710 Mar-01-2019, 01:05 PM
Last Post: buran
  new python package test ramkrishna 0 155 Feb-25-2019, 12:18 PM
Last Post: ramkrishna
  How to make loop go back to the beginning if test evaluaes to True. FWendeburg 1 224 Feb-13-2019, 01:26 AM
Last Post: stullis

Forum Jump:

Users browsing this thread: 1 Guest(s)