Pytest not properly using fixture: TypeError: test_foo() missing 1 required positional argument: 'bar'

Pytest not properly using fixture: TypeError: test_foo() missing 1 required positional argument: 'bar'

我正在 运行使用 Pycharm 进行 pytest。使用 ctrl+click.

时它会正确地跟随夹具
import pytest


@pytest.fixture(scope="session")
def bar():
    return 1


def test_foo(bar):
    pass

尝试 运行 时,我得到

ssh://noam@ML:2204/miniconda/envs/py37/bin/python -u /home/noam/.pycharm_helpers/pycharm/_jb_unittest_runner.py --target test_pre_processing.test_foo
Testing started at 20:15 ...
Launching unittests with arguments python -m unittest test_pre_processing.test_foo in /home/noam/src/algo_flows/tests

Traceback (most recent call last):
  File "/home/noam/.pycharm_helpers/pycharm/_jb_unittest_runner.py", line 35, in <module>
    sys.exit(main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING))
  File "/miniconda/envs/py37/lib/python3.7/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/miniconda/envs/py37/lib/python3.7/unittest/main.py", line 147, in parseArgs
    self.createTests()
  File "/miniconda/envs/py37/lib/python3.7/unittest/main.py", line 159, in createTests
    self.module)
  File "/miniconda/envs/py37/lib/python3.7/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/miniconda/envs/py37/lib/python3.7/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/miniconda/envs/py37/lib/python3.7/unittest/loader.py", line 205, in loadTestsFromName
    test = obj()

TypeError: test_foo() missing 1 required positional argument: 'bar'

我可以看到日志显示 should be the answer to my problem (unittest clashing with pytest), but pycharm is already configured to run pytest!

经过一番抨击后,似乎在将 pycharm 设置为 pytest over unittest 之后, 还必须删除并重新创建 run-configurations。

Credit: point 3 here