[pytest-dev] improve -k/-m exercise / want to help pytest?
holger at merlinux.eu
Sun Oct 26 10:49:50 CET 2014
On Sun, Oct 26, 2014 at 07:26 +0530, Okan bhan wrote:
> Hi Holger
> I would like to work on this but I've some very silly doubts which I would
> like to clarify. Please bear with me if I'm unclear/repeating in my views
> as this is my first time contributing to any open source project
> I tried understanding this problem and looking inside source code. With
> help from nice people on IRC, I could understand how it is implemented
> (namely matchmark & matchkeyword method in mark.py module). My issue is:
> 1. I don't understand how we can put dotted path as marker. Currently if I
> try a marker (like @pytest.mark.a.b), I get error "AttributeError:
> MarkDecorator instance has no attribute 'b'". Does this feature require a
> fix of this so that we can allow custom markers with dots.
No, sorry if that was unclear. There is no easy possibility to have
a dotted marker.
> 2. Similarly for 'keywords', in what scenario dotted path (like 4.3) will
> be a keyword? We can't put it as method_name, class_name etc. Only option
> left is parametrized testcases but I grasp this.
Parametrizing tests can add almost arbitrary string IDs and they become
part of the node id against which "-k" is matching. So "-k 1.3" might very
well be used from a user wanted to run tests functions using a particular
Does this now make sense to you?
> Please guide me to docs/links regarding this.
> Thanks & Regards
> On Wed, Oct 22, 2014 at 12:51 PM, holger krekel <holger at merlinux.eu> wrote:
> > Hi all,
> > is anyone interested in a little exercise that would improve pytest usage?
> > It doesn't require deep pytest knowledge.
> > This is about the "-k" and "-m" selection mini-language,
> > namely expressions like:
> > marker1 and marker2
> > not marker1 and (marker2 or marker3)
> > and so forth. The thing is that pytest currently uses Python's "eval" with
> > a custom dictionary which means that names such as "marker1"
> > cannot have dots or other punctuation and also other things are not
> > possible like running all tests that don't have "4.3" (coming from a
> > parametrized test) in it:
> > -k 'not 4.3'
> > This would currently select all tests because "4.3" is true. Various
> > people have run into traps like this.
> > So what is needed here are tests and code that, given a set of names
> > and an expression string, determines if the expression is true or not.
> > And everything except "and" and "or" are valid words. To use the latter
> > two words probably need to have some escaping like "\and" or so but
> > that's a bonus task :)
> > Anyone up for this little exercise? Or other comments?
> > best and thanks,
> > holger
> > _______________________________________________
> > Pytest-dev mailing list
> > Pytest-dev at python.org
> > https://mail.python.org/mailman/listinfo/pytest-dev
More information about the pytest-dev