Skip to content

Add __test__ attribute to AnyValue class for pytest - #808

Closed
oxinabox wants to merge 1 commit into
JuliaPy:mainfrom
oxinabox:patch-2
Closed

oxinabox wants to merge 1 commit into
JuliaPy:mainfrom
oxinabox:patch-2

Conversation

@oxinabox

Copy link
Copy Markdown
Contributor

I don't entirely understand why this happens.
I think it is some interaction between pytest and the python debugger and it not undestanding python code when that code is not in a .py file.

But running juliacall in the python debugger, excent with it set to only break on User Uncaught Exceptions always breaks like 2-5 times in this code, because it tried to check if it has a __test__ attribute. Which it does not.

Easiest fix is just to add it.
Though it isn't the most satisfying.

I don't entirely understand why this happens.
I think it is some interaction between pytest and the python debugger and it not undestanding python code when that code is not in a `.py` file.

But running juliacall in the python debugger, excent with it set to only break on User Uncaught Exceptions 
always breaks like 2-5 times in this code, because it tried to check if it has a `__test__` attribute.
Which it does not.

Easiest fix is just to add it.
Though it isn't the most satisfying.
@cjdoris

cjdoris commented Sep 1, 2026

Copy link
Copy Markdown
Member

The fix feels very much like a hack. Can you figure out what the actual issue is?

@oxinabox

oxinabox commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

The fix feels very much like a hack. Can you figure out what the actual issue is?

I have spend several afternoons trying to work it out.
And it is beyond me.

I think it is a complicated intraction between exactly how the python debugger in vs-code interacts with the pytest runner.
And I think it is that duriing pytest --collect the debugger settings are always "break on any exception" even if the user as said to break only on uncaught exceptions in vs-code.

@cjdoris

cjdoris commented Sep 9, 2026

Copy link
Copy Markdown
Member

Do you have a reproducer?

@oxinabox

Copy link
Copy Markdown
Contributor Author

I can try and put together a whole pixi enviroment to reproduce and upload a zip file or something.

@oxinabox

oxinabox commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Ok here is a MWE
mwe.tar.gz

extract it and then run pixi install
then start VS-code and set it up as needed with the python plugin.
And with tests set to pytest

Go into the vs-code debug setting and make sure that only "User Uncaught Exceptions" is ticked.

image

Then right click on the arrow circled next to test_dummy and click "debug test".
An exception is thrown during the collect phase:
image

AFAICT is it because pytest sees the jl object in scope,
and then tries to go and see if it contains any tests.
Which then throws a exception.
And I have never managed to find any configuration that i can set that stops it from doing this.

I think it might well be a bug in vs-code, since this exception is clearly not a "User exception escaping into library code". Since it comes from the library code.


I cannot reproduce this if i replace the main.py with

def FakeJulia():
    def __getattr__(self, k):
        raise AttributeError(k)

jl = FakeJulia()

Some how it is juliacall (or at least library code) dependant

@cjdoris

cjdoris commented Nov 1, 2026

Copy link
Copy Markdown
Member

I believe #846 fixed this.

@cjdoris cjdoris closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants