1

This is the test file that i am running.

# this file is test_define.py

import pytest

def test_it(aw_name):
    print(aw_name)

if __name__ == '__main__':
    pytest.main(['-s', 'v', '--aw_name', 'boom', 'test_define.py'])

This is the conftest file in the same directory

# conftest file
import pytest

def pytest_addoption(parser):
    parser.addoption("--aw_name", action="store")

@pytest.fixture
def aw_name(request):
    return request.config.getoption("aw_name")

Running this in terminal works properly and prints out:

% pytest -s -v --aw_name boom test_define.py

But when I run in pycharm using the play button for the "if name == 'main':" I always get a value of None. Am i missing something in the pytest.main call? I've also double checked that the interpreter is set to the same as the terminal.

jagusking
  • 11
  • 2
  • Your test expects a variable called `aw_name`, but you're passing it an argument called `--name`. – physicalattraction Apr 29 '22 at 19:36
  • @physicalattraction sorry my mistake. Typo on my end. But even when the parameter is set to "--aw_name" I still get a printed value of None when the test runs – jagusking Apr 30 '22 at 22:03
  • Where are your test files located? Is your purest play-button call for sure calling pytest from the same working directory as when you call purest from the terminal? – BLimitless Apr 30 '22 at 22:58
  • @BLimitless test file is located in the same directory as the conftest file and a __init__.py file. The interpreter in PyCharm is set properly since im using a virtual env. keep in mind when im running in terminal I have the same venv activated – jagusking May 02 '22 at 16:26

0 Answers0