-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Pass dinamically command line option into a test body #1150
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
Comments
Yes, please take a look at this section in the docs. Based on the example, you can now access the option directly instead: # content test.py
class TestSuite():
def test_case(self, my_cmd_opt):
assert my_cmd_opt != 'foo' But if you really want to set it as an attribute of the class, you can use an autouse-fixture in the class scope: class TestSuite():
my_cmd_opt = 'foo'
@pytest.fixture(autouse=True)
def setup_getopt(my_cmd_opt):
self.my_cmd_opt = my_cmd_opt
def test_case(self):
assert self.my_cmd_opt != 'foo' Hope this helps. 🍻 |
Thanks! I tried your suggestion but I get an error:
Morover I was wondering if instead of use a fixture solution, there is a chance to do that directly from a
Setting the attribute my_cmd_opt before the calling of
There is a way to do something like this? |
Sorry: @pytest.fixture(autouse=True)
def setup_getopt(self, my_cmd_opt):
self.my_cmd_opt = my_cmd_opt
It is possible, you can access the |
Thanks! but in which of the item sub-object I need to set the attribute so that the test instance can see the command line option? |
The fixture as shown by @nicoddemus is in the object itself, no need to mess around with items |
Closing due to lack of feedback |
Hi, in my use case I need to set dinamically a self attribute of a test class with a command line option, without passing explicitly the parameter to the test definition, with a plugin.
For example:
so if i run:
because I've set self.my_cmd_opt to 'alpha' instead of 'foo'
There is a way to do that?
The text was updated successfully, but these errors were encountered: