Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--daemon-start-if-needed needs ability to set custom command for starting the daemon #87

Open
ddorian opened this issue Apr 18, 2024 · 9 comments

Comments

@ddorian
Copy link

ddorian commented Apr 18, 2024

Hi,

I'm using gevent and I start pytest with:

 python -m gevent.monkey --module pytest

Using --daemon-start-if-needed breaks because it starts pytest normally. Thus need a config to set how to auto start the daemon.

@JamesHutchison
Copy link
Owner

Are you able to solve this using PYTEST_DAEMON_PYTEST_NAME (see the readme on usage)?

I believe with this:

https://pypi.org/project/pytest-gevent/

You can change the value from pytest to pytest-gevent

Its almost midnight for me so I'll check back on this tomorrow morning or afternoon. Thanks!

@JamesHutchison
Copy link
Owner

JamesHutchison commented Apr 18, 2024

Actually looking at the implementation that might not work because it's expecting a module name

args = [
                sys.executable,
                "-m",
                pytest_name,
                "--daemon",
                "--daemon-port",
                str(port),
            ]

But maybe writing a wrapper module would work.

@ddorian
Copy link
Author

ddorian commented Apr 18, 2024

I believe with this:
https://pypi.org/project/pytest-gevent/

That library is deprecated and it says to use my way in their readme https://github.com/asottile-archive/pytest-gevent

Actually looking at the implementation that might not work because it's expecting a module name

Yep it won't work, just tried some different variations.

But maybe writing a wrapper module would work.

That could be it.

@JamesHutchison
Copy link
Owner

Did the wrapper end up resolving your issue? I'm also curious about your use case because the library doesn't support running tests concurrently (it will turn off xdist via the workaround feature, for example), but maybe you need it for other reasons.

@ddorian
Copy link
Author

ddorian commented Apr 18, 2024

I wasn't able to work on the wrapper. Use case for this library is just faster test execution locally while working on the codebase.

xdist isn't related to this case, though I'm blocked there too on gevent pytest-dev/pytest-xdist#1069. I'll probably use pytest-split for multi-core running of test suite.

@JamesHutchison
Copy link
Owner

I don't recommend rerunning your whole test suite. The intended use case is the same as you see in the gif in the readme; you execute single tests or test files from the IDE. You would use the CI to automatically run a test suite for your project and in that case you wouldn't see a benefit from using the hot reloader.

@ddorian
Copy link
Author

ddorian commented Apr 18, 2024

I agree, I never mentioned xdist, you did here:

I'm also curious about your use case because the library doesn't support running tests concurrently

Maybe you thought (gevent => concurrent-tests)?

@JamesHutchison
Copy link
Owner

JamesHutchison commented Apr 18, 2024

I was just calling it out to maybe save you some time if that was your goal.

Another thing is that sys.executible in that arg list means it reuses the same application that ran it. You could change your executable to something like this (ChatGPT threw this together):

#!/bin/bash

# Store the first argument, which is assumed to be '-m'
module_flag=$1

# Store the second argument, which is the name of the module, e.g., 'pytest'
module_name=$2

# Remove the first two arguments from the list of all arguments
shift 2

# Run the python command with the modified module and the remaining arguments
python -m gevent --module $module_name "$@"

You would then invoke it like this:
my_script -m pytest --daemon-start-if-needed <path to test>

The daemon args would become:

            args = [
                "my_script",
                "-m",
                "pytest",
                "--daemon",
                "--daemon-port",
                str(port),
            ]

@ddorian
Copy link
Author

ddorian commented Apr 19, 2024

That script doesn't work. I'll just use a runfile from the IDE for now, thank you.

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

No branches or pull requests

2 participants