[pytest-dev] pytest _pytest/mark.MarkMapping behavior

Ronny Pfannschmidt opensource at ronnypfannschmidt.de
Tue Dec 5 02:35:14 EST 2017


Am Montag, den 04.12.2017, 20:29 +0300 schrieb Yury Krasouski:
> Hi Ronny,
> 
> Many thanks for explanation!
> 
> Got this idea.
> 
> I am not sure that you are right person for this question. But could
> you do a favor and suggest a prefirable way for extraction test
> marks?

right now there is literally no sane way to extract the actual marks

however since you seem to be interested only in the names, the closest
thing is 

[k for k in item.keywords if item.get_marker(k) is not None and k not
in self.ignored_tags]

-- Ronny


> 
> At the current moment this looks like:
> > mark_plugin = test_item.config.pluginmanager.getplugin('mark')
> > if mark_plugin:
> >     keywords = test_item.keywords
> >     marks =
> mark_plugin.MarkMapping.from_keywords(keywords).own_mark_names
> >     return [m for m in marks if m not in self.ignored_tags]
> 
> In other words I need a list of marks assigned with test item (test).
> 
> P.S. Or I need to duplicate logic in our plug-in from `from_keywords`
> class method?
> 
> Thank you a lot,
> Yury
> 
> 
> 2017-12-04 19:30 GMT+03:00 RonnyPfannschmidt <opensource at ronnypfannsc
> hmidt.de>:
> > 
> > Am 04.12.2017 um 16:23 schrieb Yury Krasouski:
> > > Hello Team,
> > > 
> > > To begin with, I would like to say "Thank You" for great tools.
> > > 
> > > I am writing here to ask question about _pytest/mark.MarkMapping
> > > behavior which was used in one plug-in. I noted that API is
> > > changed a little what produced issue like this: 
> > > https://github.com/reportportal/agent-python-pytest/issues/37
> > > 
> > > The fix is simple at first look: just replace _marks to
> > > own_mark_names. But I wonder about inconvenient behavior of 
> > > 
> > > > def __getitem__(self, name):
> > > >     return name in self.own_mark_names
> > > 
> > > I would expect to call list(MarkMapping) which will return list
> > > of mark names, but instead this returns infinite iterator which
> > > produced False (or True in some cases). the im
> >  
> > > What is the reason for such behavior?
> > > 
> >  the implementation of MarkMapping is only complete enough to
> > fulfill its internal use case
> > it has no correct iteration behavior implemented, thus the fallback
> > of python breaks
> > 
> > any use of this class outside of the code path it was hacked up for
> > is likely completely incorrect
> > 
> > -- Ronny
> > 
> > 
> > > Thanks,
> > > Yury
> > > 
> > > 
> > > _______________________________________________
> > > pytest-dev mailing list
> > > pytest-dev at python.org
> > > https://mail.python.org/mailman/listinfo/pytest-dev
> >  
> 
> 


More information about the pytest-dev mailing list