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
  Test a file for a string without opening it? tester_V 2 54 7 hours ago
Last Post: tester_V
  Pytest and rootdirectory Master_Sergius 4 182 Jun-01-2020, 05:05 PM
Last Post: Master_Sergius
  How to create an Excel app that runs Python? felipe0216 3 160 May-31-2020, 01:19 AM
Last Post: ibutun
  pytest in CircleCI filepath error alyflex 0 93 Apr-20-2020, 04:39 PM
Last Post: alyflex
  PyTest >> Yaml parsed data to create api test request AmR 0 103 Apr-14-2020, 11:41 AM
Last Post: AmR
  Python Program Runs in Pycharm but not in Terminal Vbhardwaj2383 2 230 Apr-06-2020, 04:41 PM
Last Post: Vbhardwaj2383
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 471 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 156 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn
  How to execute code WHILE a function runs t4keheart 4 251 Jan-27-2020, 01:47 PM
Last Post: t4keheart
  Pytest API Post call thrown errors pyseeker 4 434 Dec-08-2019, 04:53 PM
Last Post: pyseeker

Forum Jump:

Users browsing this thread: 1 Guest(s)