Skip to content

Add shared_session_scope_pickle for arbitrary object support#37

Merged
StefanBRas merged 3 commits into
StefanBRas:mainfrom
phihos:pickle-support
Aug 17, 2025
Merged

Add shared_session_scope_pickle for arbitrary object support#37
StefanBRas merged 3 commits into
StefanBRas:mainfrom
phihos:pickle-support

Conversation

@phihos

@phihos phihos commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

Adds support for serializing arbitrary Python objects by introducing shared_session_scope_pickle which uses pickle instead of JSON. This eliminates the need for custom serialization functions when working with non-JSON serializable objects like class instances.

The implementation adds a new PickleStore class and convenience function, with updated documentation positioning pickle as the preferred option for arbitrary objects.

- Add PickleStore class using pickle serialization
- Add shared_session_scope_pickle function as convenience wrapper
- Update documentation with pickle examples
- Add test coverage for pickle functionality
@StefanBRas

Copy link
Copy Markdown
Owner

Thanks for the PR - it looks good to me, I'll probably merge it and make a release over the weekend.

I'm very interested in hearing your experience with the package. To be honest I didn't think that anyone was actually using it. I'm hoping to pick up development and fix the edge cases soon-ish, but since i've not myself really using it right now I'm not sure how useful it is in this state

@phihos

phihos commented Aug 15, 2025

Copy link
Copy Markdown
Contributor Author

Hey, thanks for looking into my PR so quickly :-)

I'm very interested in hearing your experience with the package.

Well I have acceptance tests where I spin up a kubernetes cluster via pytest-kind. This alone consumes about 30s of time. Once I introduced pytest-xdist the sessions scoped "kind_cluster" and "container_image" fixtures did run in every process, which was slow and even caused race-conditions (shared kubeconfig on disk). So I did some research and found this in the xdist documentation. The approach worked, but my code looked really ugly. Then I had the issue that whichever process finished first tore down the kubernetes cluster and all other tests broke. I am no programming novice, but I am not deep enough into the low level stuff about how to elegantly determine with locks or similar which process is last.
So I googled a bit more and found your project. And the double yield-hack seems elegant enough to me. So I used it, but found that it currently lacks support for generic object and implemented a custom store. It worked so I decided to contribute it. And here I am :-D

@StefanBRas

Copy link
Copy Markdown
Owner

Cool, thanks for letting me know! I was afraid that the limitations was too big in the current state to actually use it in projects, but nice to know that it might not be like that.

I took the liberty of pushing some smaller changes to the PR but in general it was very nicely done. Thanks! Will merge and release now

@StefanBRas StefanBRas merged commit bb646db into StefanBRas:main Aug 17, 2025
1 check passed
@StefanBRas

Copy link
Copy Markdown
Owner

v0.5.0 is released with this included, thanks!

@phihos

phihos commented Aug 17, 2025

Copy link
Copy Markdown
Contributor Author

Hi, thank you very much for merging this and even creating a new release.

Cool, thanks for letting me know! I was afraid that the limitations was too big in the current state to actually use it in projects, but nice to know that it might not be like that.

Your documentation showed multiple places to hook custom logic into. So I think it is very well usable. And I am not using -x or request.getfixturevalue() so the limitations do not really affect me.

Thank you btw for being active in OSS. Every bit helps. Like this little gem for example :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants