Skip to content

Pass dinamically command line option into a test body #1150

Closed
@fontealpina

Description

@fontealpina

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:

# content test.py 
class TestSuite():
     my_cmd_opt = 'foo'

     def test_case(self):
          assert self.my_cmd_opt != 'foo' # here the test should pass because self.my_cmd_opt
                                          # has been dinamically changed from pytest

so if i run:

   $> pytest --set-my-cmd-opt=alpha test.py
   test.py::TestSuite::test_case PASSED

because I've set self.my_cmd_opt to 'alpha' instead of 'foo'
There is a way to do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions