1

I am running a pytest with Pycharm. It follows the fixture correctly when using ctrl+click.

import pytest


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


def test_foo(bar):
    pass

When trying to run, I am getting

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'

I can see the logs show this should be the answer to my problem (unittest clashing with pytest), but pycharm is already configured to run pytest!

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • (a) from the error, it looks like you're not running `pytest` but are instead running `python -m unittest`, and (b) if I just run `pytest`, your example workers without errors. – larsks May 09 '22 at 17:26
  • Does this answer your question? [How do I configure PyCharm to run py.test tests?](https://stackoverflow.com/questions/6397063/how-do-i-configure-pycharm-to-run-py-test-tests) – bad_coder May 10 '22 at 01:39
  • @bad_coder it does, but required reading through the entire thing. SO's duplicate mechanism doesn't point to an answer, but to a question, which isn't ideal. – Gulzar May 10 '22 at 09:46
  • 1
    @Gulzar I'm going to give you an upvote so the question doesn't get deleted because there's only 1 more question for this error message tagged `pycharm` and `pytest`. So it's useful as a road sign to give a direct hit. – bad_coder May 10 '22 at 13:15
  • This is a reasonable question and should be reopened.: the source of the problem is a bug in `pycharm` that we can all easily run into . – WestCoastProjects Jul 14 '23 at 02:49

1 Answers1

4

After some head bashing, it seems that after setting pycharm to pytest over unittest, one must also remove and recreate the run-configurations.

Credit: point 3 here

Gulzar
  • 23,452
  • 27
  • 113
  • 201