Pytest: Allow test selection by file:lineno

Created on 14 Feb 2018  路  12Comments  路  Source: pytest-dev/pytest

pytest tests/test_foo.py:42 should run the (nearest) test at line 42 in tests/test_foo.py.

When it also ignores a trailing colon it would allow for easy copy'n'pasting from failures.

Via #5973:

To get a better overview of how it can work take a look at the Rspec documentation

selection enhancement

All 12 comments

Great idea!

How do we pick the nearest test? Assuming, we have a following file:

def test_1():
     assert True

def test_2():
     assert False

If the user will pick line 3, should it match test_1 or test_2?
What if the line number falls in the fixture definition?

picking whitespace or non test functions should result in a collection error and not running any tests

s/whitespace/whitespace between test functions/

one must pick a line within the test function body

In case you are interested: I am taking at stab at this in https://github.com/blueyed/pytest/pull/42, since I have "file:lnum" in summaries now (https://github.com/blueyed/pytest/pull/38).

@blueyed Please don't close issues here for things you only fixed in your fork (instead of here)...

@The-Compiler
This is done automatically (Github bug/issue?) - maybe only for issues reported by myself?
I will usually re-open them then if applicable (when going through my notifications).

Just for reference, since I've found this issue again: I'm using this myself since a while, and it is very nice (as expected ;) - I know why I've asked about it several times, and am glad I've just tried it instead of adhering to the "this is blocked due to necessary refactorings"). /cc @feuillemorte

The next step would be using ranges here, e.g. fname:lnum- would run everything after that given line (useful from git diffs, where you want to run anything after a given / changed line).

hey @blueyed thanks for this feature! I've just imagined this exactly like it is, and while I was writing an issue with the proposal, github showed me this one as a "related issue". What a synced community!

regarding the range support, would be great to also support an endline number instead to assume it's from lnum until the eof, so I could select a range in my editor and run "all the selected tests".

Moreover, it could mimic the python's slices behavior:

  • fname:fromline-endline,
  • fname:-endline (assumes "from the beginning)
  • fname:fromline- (assumes "until the end")

As OP I'm closing it again: it's fixed for me (literally).

What's the status of this?

I've found this code by @asfaltboy that basically solves the parsing problem using stdlib's ast.

Hi @mgaitan,

Thanks for the link!

It is still open and AFAIK nobody is working on this currently.

Was this page helpful?
0 / 5 - 0 ratings