Open GitBharath opened 5 years ago
@kevlened @nicodemus
@nicoddemus
Hi,
Sorry I'm in a hurry so I don't have time to look at the code of pytest-parallel
in detail:
-n3
being passed here, given that -n
is used by pytest-xdist?pytest-parallel
?addopts
in pytest_configure
will have any effect, regardless of pytest-parallel
; by the time pytest_configure
has been called, the arguments have already been processed by pytest.Why is -n3 being passed here, given that -n is used by pytest-xdist?
I parsed -n3
so that the xdist runs on 3 subprocesses
Does the behavior change when run with or without pytest-parallel?
No. But If you have time; please look into the other bug #34
I don't think changing addopts in pytest_configure will have any effect, regardless of pytest-parallel; by the time pytest_configure has been called, the arguments have already been processed by pytest
I need to somehow configure the addopts either in command line or pytest.ini.
I parsed -n3 so that the xdist runs on 3 subprocesses
I'm a little confused because this is the issue tracker for pytest-parallel
... does pytest-parallel
uses pytest-xdist
somehow?
No. But If you have time; please look into the other bug #34
Sorry, I fail to see the connection with what's being discussed here. 😬
I need to somehow configure the addopts either in command line or pytest.ini.
Doesn't really make sense to configure addopts
from the command-line, given that addopts
is to implicitly add options to the command-line. addopts
in pytest.ini is just a matter of writing the options there...
Can you explain exactly what you are trying to accomplish (rather than how)?
I'm a little confused because this is the issue tracker for pytest-parallel... does pytest-parallel uses pytest-xdist somehow?
yes it uses pytest-xdist that is the reason I am giving the flag -n
here
Sorry, I fail to see the connection with what's being discussed here.
There is no connection, please look into it sometime later, let's discuss on the current issue
Can you explain exactly what you are trying to accomplish (rather than how)?
My attempt is to append the flag -n=[num_of_environments_parsed_in_cmd_line]
to pytest.ini dynamically with hooks or custom plugins. Have tried with several hooks like pytest_cmdline_main
, pytest_cmdline_preparse
, pytest_cmdline_parse
and pytest_configure
. but unable to get what I wanted.
In order to resolve the issue, I have gone through the issues and comments raised by some people with similar attempts in bugs "https://github.com/pytest-dev/pytest/issues/3302" and "https://github.com/pytest-dev/pytest/issues/1150". But no help found with the comments given.
Thanks! OK, now things are starting to click together for me. 👍
It does not seem to be possible to actually change the command-line arguments via a plugin, because it is processed very early in the initialization process.
You can however change the option directly in a hook:
# conftest.py
def pytest_cmdline_preparse(config, args):
config.option.numprocesses = 2
pytest-xdist
will check config.option.numprocesses
during pytest_cmdline_main
:
Ok thanks for the answer. I was just having a weird thought that if we somehow put the command line to a mediator test data before processing/do initial configuring immediately to run the scripts. And configuration can happen according to the parsed test data.
Command line --> test data --> *.ini/.cfg files --> test scripts run
Not sure if this is a good idea. Maybe we can close this off.
But do let me know your comments. Thanks.
I was just having a weird thought that if we somehow put the command line to a mediator test data before processing/do initial configuring immediately to run the scripts. And configuration can happen according to the parsed test data.
Currently this is tricky, because command-options can be used to control plugin loading, for example -p
.
I'm a little confused because this is the issue tracker for pytest-parallel... does pytest-parallel uses pytest-xdist somehow?
yes it uses pytest-xdist that is the reason I am giving the flag
-n
here
pytest-parallel
doesn't use pytest-xdist
; it monkey-patches pytest with multiprocessing and thread-safe data structures.
Thanks! OK, now things are starting to click together for me. 👍
It does not seem to be possible to actually change the command-line arguments via a plugin, because it is processed very early in the initialization process.
You can however change the option directly in a hook:
# conftest.py def pytest_cmdline_preparse(config, args): config.option.numprocesses = 2
pytest-xdist
will checkconfig.option.numprocesses
duringpytest_cmdline_main
:
you saved my day works on xdist too
Objective:
Adding
-n [var_num]
to addopts for my pytest.ini file wherein the var_num is dynamically taken accordingly from command line for pytest-xdist run.My project struct:
pytest.ini
conftest.py
output is
Expected Output
Expectation was should be same as when I parse the
-n
flag topytest.ini
pytest.ini
conftest.py
Result is shown as below
As you see even if both the pytest.ini addopts having the same list of data, the resulting behaviour is different. The first attempt is not even considering the flag
-n
. What is the reason for this ? How to get this fixed ?EDIT
If I add both the pytest.ini and conftest.py files; the list data is