Skip to content

Test collection fails in IntelliJ #128

@edwinnazarian

Description

@edwinnazarian

Here is my test condition that I set up in PyCharm (IntelliJ):

[Cell 1]

__file__ = "test_ipytest.ipynb"

import ipytest
ipytest.config(raise_on_error=True, coverage=False)

[Cell 2]

%%ipytest

import pytest

def test_simple():
    assert simple()

def simple():
    return True

I first run the Cell1. Cell 1's output is:

{'addopts': ('-q', '--color=yes'),
'clean': '[Tt]est*',
'coverage': False,
'defopts': 'auto',
'display_columns': 100,
'magics': True,
'raise_on_error': True,
'rewrite_asserts': True,
'run_in_thread': False}

Then I run Cell 2. Cell 2's output is:

no tests ran in 0.00s

Error Traceback (most recent call last)
Cell In[54], line 1
----> 1 get_ipython().run_cell_magic('ipytest', '', '\nimport pytest\n\ndef test_simple():\n assert simple()\n\ndef simple():\n return True\n\n')

File ~/IPytestProject/.venv/lib/python3.12/site-packages/IPython/core/interactiveshell.py:2542, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
2540 with self.builtin_trap:
2541 args = (magic_arg_s, cell)
-> 2542 result = fn(*args, **kwargs)
2544 # The code below prevents the output from being displayed
2545 # when using magics with decorator @output_can_be_silenced
2546 # when the last Python token in the expression is a ';'.
2547 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/IPytestProject/.venv/lib/python3.12/site-packages/ipytest/_impl.py:166, in ipytest_magic(line, cell, module)
158 raise RuntimeError(
159 "The ipytest magic cannot evaluate the cell. Most likely you "
160 "are running a modified ipython version. Consider using "
161 "ipytest.run and ipytest.clean directly.",
162 ) from e
164 raise e
--> 166 run(*run_args, **run_kwargs)

File ~/IPytestProject/.venv/lib/python3.12/site-packages/ipytest/_impl.py:89, in run(module, plugins, run_in_thread, raise_on_error, addopts, defopts, display_columns, coverage, *args)
86 ipytest.exit_code = exit_code
88 if raise_on_error is True and exit_code != 0:
---> 89 raise Error(exit_code)
91 return exit_code

Error: ipytest failed with exit_code 5

Not sure why it thinks I might be running a modified ipython. Not sure why my test method is not executed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions