test_ok2/changelog
Ran Benita d18cb961cf assertion/rewrite: fix internal error on collection error due to decorated function
For decorated functions, the lineno of the FunctionDef AST node points
to the `def` line, not to the first decorator line. On the other hand,
in code objects, the `co_firstlineno` points to the first decorator
line.

Assertion rewriting inserts some imports to code it rewrites. The
imports are inserted at the lineno of the first statement in the AST. In
turn, the code object compiled from the rewritten AST uses the lineno of
the first statement (which is the first inserted import).

This means that given a module like this,

```py
@foo
@bar
def baz(): pass
```

the lineno of the code object without assertion rewriting
(`--assertion=plain`) is 1, but with assertion rewriting it is 3.

And *this* causes some issues for the exception repr when e.g. the
decorator line is invalid and raises during collection. The code becomes
confused and crashes with

INTERNALERROR>   File "_pytest/_code/code.py", line 638, in get_source
INTERNALERROR>     lines.append(space_prefix + source.lines[line_index].strip())
INTERNALERROR> IndexError: list index out of range

Fix it by special casing decorators. Maybe there are other cases like
this but off hand I can't think of another Python construct where the
lineno of the item would be after its first line, and this is the only
such issue we have had reported.
2020-09-12 23:05:08 +03:00
..
1477.doc.rst Remove faq.rst from docs (#7635) 2020-08-12 14:47:34 -03:00
1953.bugfix.rst Allow ovewriting a parametrized fixture while reusing the parent fixture's value 2020-09-11 16:53:34 -03:00
4984.bugfix.rst assertion/rewrite: fix internal error on collection error due to decorated function 2020-09-12 23:05:08 +03:00
5585.breaking.rst Remove resultlog plugin 2020-08-19 08:14:28 -03:00
6681.improvement.rst Integrate warnings filtering directly into Config (#7700) 2020-09-04 11:57:15 -03:00
6981.deprecation.rst Reintroduce warnings postponed in 6.0 (#7637) 2020-08-22 11:17:50 -03:00
7097.deprecation.rst Reintroduce warnings postponed in 6.0 (#7637) 2020-08-22 11:17:50 -03:00
7210.deprecation.rst Reintroduce warnings postponed in 6.0 (#7637) 2020-08-22 11:17:50 -03:00
7255.deprecation.rst Reintroduce warnings postponed in 6.0 (#7637) 2020-08-22 11:17:50 -03:00
7536.trivial.rst junitxml: convert from py.xml to xml.etree.ElementTree 2020-07-29 10:52:21 +03:00
7587.trivial.rst Stop using more-itertools 2020-07-30 20:19:24 +03:00
7591.bugfix.rst Only define gethookproxy, isinitpath on Session 2020-08-15 13:40:16 +03:00
7628.bugfix.rst Fix Module.name from full path without drive letter 2020-08-15 09:39:14 -03:00
7631.trivial.rst Add changelog for PR #7631 2020-08-14 11:02:44 +03:00
7638.bugfix.rst get_dirs_from_args handles paths with invalid syntax 2020-08-12 17:20:09 -03:00
7648.deprecation.rst Only define gethookproxy, isinitpath on Session 2020-08-15 13:40:16 +03:00
7667.feature.rst Make min duration configurable for slowest tests (#7667) 2020-09-05 09:18:29 -03:00
7671.trivial.rst python: skip pytest_pycollect_makeitem work on certain names 2020-08-26 17:43:57 +03:00
7685.improvement.rst config: add Config.{rootpath,inipath}, turn Config.{rootdir,inifile} to properties 2020-09-04 18:04:25 +03:00
7742.bugfix.rst Fix INTERNALERROR when accessing locals / globals with faulty `exec` 2020-09-11 18:13:48 -07:00
README.rst docs: use doc/en/_build/html for html output (#6842) 2020-02-29 00:47:30 +01:00
_template.rst Update CHANGELOG template to put issue links at the start of entries 2018-07-07 11:02:33 -03:00

README.rst

This directory contains "newsfragments" which are short files that contain a small **ReST**-formatted
text that will be added to the next ``CHANGELOG``.

The ``CHANGELOG`` will be read by **users**, so this description should be aimed to pytest users
instead of describing internal changes which are only relevant to the developers.

Make sure to use full sentences in the **past or present tense** and use punctuation, examples::

    Improved verbose diff output with sequences.

    Terminal summary statistics now use multiple colors.

Each file should be named like ``<ISSUE>.<TYPE>.rst``, where
``<ISSUE>`` is an issue number, and ``<TYPE>`` is one of:

* ``feature``: new user facing features, like new command-line options and new behavior.
* ``improvement``: improvement of existing functionality, usually without requiring user intervention (for example, new fields being written in ``--junitxml``, improved colors in terminal, etc).
* ``bugfix``: fixes a bug.
* ``doc``: documentation improvement, like rewording an entire session or adding missing docs.
* ``deprecation``: feature deprecation.
* ``breaking``: a change which may break existing suites, such as feature removal or behavior change.
* ``vendor``: changes in packages vendored in pytest.
* ``trivial``: fixing a small typo or internal change that might be noteworthy.

So for example: ``123.feature.rst``, ``456.bugfix.rst``.

If your PR fixes an issue, use that number here. If there is no issue,
then after you submit the PR and get the PR number you can add a
changelog using that instead.

If you are not sure what issue type to use, don't hesitate to ask in your PR.

``towncrier`` preserves multiple paragraphs and formatting (code blocks, lists, and so on), but for entries
other than ``features`` it is usually better to stick to a single paragraph to keep it concise.

You can also run ``tox -e docs`` to build the documentation
with the draft changelog (``doc/en/_build/html/changelog.html``) if you want to get a preview of how your change will look in the final release notes.