summaryrefslogtreecommitdiff
path: root/testing/test_pytester.py
AgeCommit message (Collapse)Author
2020-12-18address commentsantonblr
2020-12-18tests: Migrate to pytester - final updateantonblr
2020-11-21Add str() support to LineMatcher (#8050)Maximilian Cosmo Sitter
2020-10-25testing: use pytester.spawn instead of testdirRan Benita
Part of investigating a bug, but didn't fix it.
2020-10-12New pytester fixture (#7854)Bruno Oliveira
2020-10-05py36+: com2annAnthony Sottile
2020-10-03py36+: pyupgrade: py36+Anthony Sottile
2020-08-04typing: set warn_unreachableRan Benita
This makes mypy raise an error whenever it detects code which is statically unreachable, e.g. x: int if isinstance(x, str): ... # Statement is unreachable [unreachable] This is really neat and finds quite a few logic and typing bugs. Sometimes the code is intentionally unreachable in terms of types, e.g. raising TypeError when a function is given an argument with a wrong type. In these cases a `type: ignore[unreachable]` is needed, but I think it's a nice code hint.
2020-08-03testing: fix some docstring issuesRan Benita
In preparation for enforcing some docstring lints.
2020-07-10Remove no longer needed `noqa: F821` usesRan Benita
Not needed since pyflakes 2.2.0.
2020-06-13assertoutcomes() only accepts plural formsBruno Oliveira
Fix #6505
2020-05-12mark: reuse compiled expression for all items in -k/-mRan Benita
The previous commit made this possible, so utilize it. Since legacy.py becomes pretty bare, I inlined it into __init__.py. I'm not sure it's really "legacy" anyway! Using a simple 50000 items benchmark with `--collect-only -k nomatch`: Before (two commits ago): ======================== 50000 deselected in 10.31s ===================== 19129345 function calls (18275596 primitive calls) in 10.634 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.001 0.001 2.270 2.270 __init__.py:149(pytest_collection_modifyitems) 1 0.036 0.036 2.270 2.270 __init__.py:104(deselect_by_keyword) 50000 0.055 0.000 2.226 0.000 legacy.py:87(matchkeyword) After: ======================== 50000 deselected in 9.37s ========================= 18029363 function calls (17175972 primitive calls) in 9.701 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 1.394 1.394 __init__.py:239(pytest_collection_modifyitems) 1 0.057 0.057 1.393 1.393 __init__.py:162(deselect_by_keyword) The matching itself can be optimized more but that's a different story.
2020-04-08Update testing/test_pytester.pyDaniel Hahler
Co-Authored-By: Ran Benita <ran@unusedvar.com>
2020-04-06Fix `test_popen_default_stdin_stderr_and_stdin_None` when run with `-s`Daniel Hahler
2020-03-04Fix usage of pytester with doctests (#6802)Daniel Hahler
Use `request.node.name` instead of `request.function.__name__`: `request.function` is `None` with `DoctestItem`s.
2020-02-18Use a hack to make typing of pytest.fail.Exception & co workRan Benita
Mypy currently is unable to handle assigning attributes on function: https://github.com/python/mypy/issues/2087. pytest uses this for the outcome exceptions -- `pytest.fail.Exception`, `pytest.exit.Exception` etc, and this is the canonical name by which they are referred. Initially we started working around this with type: ignores, and later by switching e.g. `pytest.fail.Exception` with the direct exception `Failed`. But this causes a lot of churn and is not as nice. And I also found that some code relies on it, in skipping.py: def pytest_configure(config): if config.option.runxfail: # yay a hack import pytest old = pytest.xfail config._cleanup.append(lambda: setattr(pytest, "xfail", old)) def nop(*args, **kwargs): pass nop.Exception = xfail.Exception setattr(pytest, "xfail", nop) ... So it seems better to support it. Use a hack to make it work. The rest of the commit rolls back all of the workarounds we added up to now. `pytest.raises.Exception` also exists, but it's not used much so I kept it as-is for now. Hopefully in the future mypy supports this and this ugliness can be removed.
2020-02-10Move ExitCode's definition from _pytest.main to _pytest.configRan Benita
ExitCode is used in several internal modules and hooks and so with type annotations added, needs to be imported a lot. _pytest.main, being the entry point, generally sits at the top of the import tree. So, it's not great to have ExitCode defined in _pytest.main, because it will cause a lot of import cycles once type annotations are added (in fact there is already one, which this change removes). Move it to _pytest.config instead. _pytest.main still imports ExitCode, so importing from there still works, although external users should really be importing from `pytest`.
2020-02-04pytester: LineMatcher: typing, docs, consecutive line matching (#6653)Daniel Hahler
2020-02-01pytester.LineMatcher: add support for matching lines consecutivelyDaniel Hahler
2020-02-01typing: pytester: LineMatcherDaniel Hahler
2020-02-01Use TypeError instead of AssertionError for no sequenceDaniel Hahler
Improve/extends tests.
2020-02-01testing/test_pytester.py: cosmeticsDaniel Hahler
2020-01-29Merge master into featuresDaniel Hahler
2020-01-27pytester: test for _makefile joining an absolute pathDaniel Hahler
Ref: https://github.com/pytest-dev/pytest/pull/6578#discussion_r371035867
2020-01-22Merge master into featuresDaniel Hahler
2020-01-22Merge remote-tracking branch 'upstream/master' into mmBruno Oliveira
Conflicts: * src/_pytest/_code/code.py * src/_pytest/main.py * testing/python/metafunc.py * testing/test_parseopt.py * testing/test_pytester.py
2020-01-22tests: fix test_cwd_snapshotDaniel Hahler
Without restoring the cwd, successive tests might fail to parse the config (via `_pytest.config._prepareconfig()`, for when `--lsof` is used). And it is good practice to restore the cwd in any case anyway.
2020-01-19Fix check_untyped_defs errors in test_pytesterRan Benita
2020-01-10Merge master into featuresDaniel Hahler
2019-12-30Fix `RunResult.parseoutcomes` (follow-up to #6353)Daniel Hahler
2019-12-18pytester: quick fix error introduced in #5990Alexandre Mulatinho
- added a test to check this condition Signed-off-by: Alexandre Mulatinho <alex@mulatinho.net>
2019-11-22pytester: remove special handling of env during inner runsDaniel Hahler
Closes https://github.com/pytest-dev/pytest/issues/6213.
2019-11-20pytester: reset log output in _match_lines (#70)Daniel Hahler
This is necessary for when using e.g. `no_fnmatch_line` after it. Factor it out into `_fail`. (cherry picked from commit aade7ed0045ba32557ef8565cbab28a2c91053a7) Ref: https://github.com/pytest-dev/pytest/pull/5914#issuecomment-549182242
2019-10-27pytester: typingDaniel Hahler
2019-10-24pytester: align prefixes (#6026)Bruno Oliveira
pytester: align prefixes
2019-10-24pytester: align prefixesDaniel Hahler
This is important for using another match_nickname, e.g. "re.match". TODO: - [ ] changelog - [ ] test
2019-10-23Show the mnemonic of pytest.ExitCode in RunResult's reprBruno Oliveira
Fix #4901
2019-10-06Introduce no_fnmatch_line/no_re_match_line in pytesterBruno Oliveira
The current idiom is to use: assert re.match(pat, result.stdout.str()) Or assert line in result.stdout.str() But this does not really give good results when it fails. Those new functions produce similar output to ther other match lines functions.
2019-08-10Show session duration in human-readable formatBruno Oliveira
Fix #5707
2019-08-02Merge master into featuresDaniel Hahler
Several conflicts, mostly due to 2c402f4bd. Conflicts: .pre-commit-config.yaml src/_pytest/outcomes.py src/_pytest/python_api.py tox.ini
2019-07-20Fix ordering of sys modules snapshotAnthony Sottile
2019-06-30Remove 'pytest.config'Bruno Oliveira
2019-06-15initial conversion of exit codes to enumRonny Pfannschmidt
2019-06-06small mypy fixesAnthony Sottile
2019-06-04Clean up u' prefixes and py2 bytes conversionsAnthony Sottile
2019-06-03pre-commit run pyupgrade --all-filesAnthony Sottile
2019-06-03pre-commit run reorder-python-imports --all-filesAnthony Sottile
2019-06-03pre-commit run fix-encoding-pragma --all-filesAnthony Sottile
2019-05-30pytester: factor out testdir._env_run_updateDaniel Hahler
2019-05-30pytester: use temporary HOME with spawnDaniel Hahler
Followup to https://github.com/pytest-dev/pytest/issues/4956.