You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating an User interface to select and deselect tests after test collection. I am considering item.add_marker(pytest.mark.skip) to achieve that; But I didn't find remove_marker option in pytest collected item. Why is so? Is there a way I can dynamically remove marker from the collected item?
Below is the custom plugin I developed to show the tests after it gets collected in a UI which has check boxes. I want to provide an option for user to override pytest.mark.skip written in the code to select or deselect tests.
importpytest_testView.listVieweraslistViewerimportpytest, pdbimport_pytestimportnatsort__dictKeys= ("file", "line", "test")
classItemViewModel(object):
def__init__(self, itemObj, outcome=""):
self.item=itemObjself.__outcome=outcomeself.__notes=""@propertydeffile(self):
returnself.item.location[0]
@propertydefline(self):
returnself.item.location[1]
@propertydeftest(self):
returnself.item.location[2]
@propertydefoutcome(self):
returnself.__outcome@propertydefnotes(self):
returnself.__notesdefisSelected(self):
if (isinstance(self.item, _pytest.python.Function)):
ifself.item.get_marker("skip"):
returnFalseelse:
returnTrueelse:
returnNonedefonSelectionChanged(self, state):
#pdb.set_trace()if (isinstance(self.item, _pytest.python.Function)):
if (state):
print ("Test is marked to skip; Can't enable in UI")
#self.item.remove_marker("skip")# There is no method to remove the markerelse:
self.item.add_marker("skip")
defmakeTestItemCollection(l_testItems):
#for item in l_testItems:# yield ItemViewModel(item)l_d_testObjs= []
foriteminl_testItems:
l_d_testObjs.append(ItemViewModel(item))
returnl_d_testObjsdefshowTestItems(l_testItems):
__frameBuilder=listViewer.FrameBuilder()
__frameBuilder.showTests(makeTestItemCollection(l_testItems))
__frameBuilder.showFrame()
defpytest_addoption(parser):
"""Add the '--reorder' argument to the py.test invocation."""group=parser.getgroup('tests viewer', 'viewTests', after='general')
group.addoption(
'--viewTests', type=str, nargs='*',
help=(
"Shows the tests collected in a viewer after the tests are collected "
)
)
@pytest.hookimpl(trylast=True) # This is mandatory so that the sorting happens lastdefpytest_collection_modifyitems(session, config, items):
items.sort(key=natsort.natsort_keygen(key=lambdax: x._genid))
items.sort(key=natsort.natsort_keygen(key=lambdax: x.location[0]))
#------- SORT TESTS -----viewerOption=config.getoption("viewTests")
if (viewerOption==None):
returnelse:
showTestItems(items)
The text was updated successfully, but these errors were encountered:
@satishmovvar there is no support to dynamically remove markers, and the data structures in the keywords mapping are polymorphic meaning its very likely you will end up with a broken code unless you are really really carefull
in addition markers and their handling will soon moved to a own internal structure meaning your code wont work with the next pytest feature release
both the new storage and the current storage are not meant to be modified from the outside - so expect breakage
please consider introducing a custom mark and adding skip markers for tests the user wants to skip
I am creating an User interface to select and deselect tests after test collection. I am considering item.add_marker(pytest.mark.skip) to achieve that; But I didn't find remove_marker option in pytest collected item. Why is so? Is there a way I can dynamically remove marker from the collected item?
Below is the custom plugin I developed to show the tests after it gets collected in a UI which has check boxes. I want to provide an option for user to override pytest.mark.skip written in the code to select or deselect tests.

The text was updated successfully, but these errors were encountered: