Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
youtux committed Nov 5, 2022
2 parents a2eed97 + ef05a54 commit 1d88511
Show file tree
Hide file tree
Showing 41 changed files with 609 additions and 606 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools
pip install tox tox-gh-actions codecov
pip install tox tox-gh-actions coverage[toml]
- name: Type checking
continue-on-error: true
run: |
tox -e mypy
- name: Test with tox
run: |
coverage erase
tox
codecov
coverage combine
coverage xml
- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true # optional (default = false)
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Unreleased
- Add ``stacklevel`` param to ``given``, ``when``, ``then``, ``step`` decorators. This allows for programmatic step generation `#548 <https://github.com/pytest-dev/pytest-bdd/pull/548>`_
- Hide pytest-bdd internal method in user tracebacks `#557 <https://github.com/pytest-dev/pytest-bdd/pull/557>`_.
- Make the package PEP 561-compatible `#559 <https://github.com/pytest-dev/pytest-bdd/issues/559>`_ `#563 <https://github.com/pytest-dev/pytest-bdd/pull/563>`_.
- Configuration option ``bdd_features_base_dir`` is interpreted as relative to the `pytest root directory <https://docs.pytest.org/en/latest/reference/customize.html#rootdir>`_ (previously it was relative to the current working directory). `#573 <https://github.com/pytest-dev/pytest-bdd/pull/573>`_


6.0.1
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ then
Feature file paths
------------------

By default, pytest-bdd will use current module's path as base path for finding feature files, but this behaviour can be changed in the pytest configuration file (i.e. `pytest.ini`, `tox.ini` or `setup.cfg`) by declaring the new base path in the `bdd_features_base_dir` key. The path is interpreted as relative to the working directory when starting pytest.
By default, pytest-bdd will use current module's path as base path for finding feature files, but this behaviour can be changed in the pytest configuration file (i.e. `pytest.ini`, `tox.ini` or `setup.cfg`) by declaring the new base path in the `bdd_features_base_dir` key. The path is interpreted as relative to the `pytest root directory <https://docs.pytest.org/en/latest/reference/customize.html#rootdir>`__.
You can also override features base path on a per-scenario basis, in order to override the path for specific tests.

pytest.ini:
Expand Down
316 changes: 146 additions & 170 deletions poetry.lock

Large diffs are not rendered by default.

36 changes: 23 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,27 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.7"
glob2 = "*"
Mako = "*"
parse = "*"
parse-type = "*"
pytest = ">=6.2.0"
typing-extensions = "*"

[tool.poetry.dev-dependencies]
tox = "^3.25.1"
mypy = "^0.971"
types-setuptools = "^64.0.1"
pytest-xdist = "^2.5.0"
coverage = {extras = ["toml"], version = "^6.4.3"}
Pygments = "^2.12.0" # for code-block highlighting
[tool.poetry.group.dev.dependencies]
tox = "^3.27.0"
mypy = "^0.982"
types-setuptools = "^65.5.0.2"
pytest-xdist = "^3.0.2"
coverage = {extras = ["toml"], version = "^6.5.0"}
Pygments = "^2.13.0" # for code-block highlighting

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 120
target-version = ["py37", "py38", "py39", "py310"]
target-version = ["py37", "py38", "py39", "py310", "py311"]

[tool.isort]
profile = "black"
Expand All @@ -68,11 +67,22 @@ exclude_lines = [
"if TYPE_CHECKING:",
"if typing\\.TYPE_CHECKING:",
]
[tool.coverage.html]
show_contexts = true

[tool.coverage.run]
branch = true
include =[
"src/pytest_bdd/*",
"tests/*",
# `parallel` will cause each tox env to put data into a different file, so that we can combine them later
parallel = true
source = ["pytest_bdd", "tests"]
dynamic_context = "test_function"

[tool.coverage.paths]
# treat these directories as the same when combining
# the first item is going to be the canonical dir
source = [
"src/pytest_bdd",
".tox/*/lib/python*/site-packages/pytest_bdd",
]


Expand All @@ -83,5 +93,5 @@ warn_unused_configs = true
files = "src/pytest_bdd/**/*.py"

[[tool.mypy.overrides]]
module = ["parse", "parse_type", "glob2"]
module = ["parse", "parse_type"]
ignore_missing_imports = true
7 changes: 4 additions & 3 deletions src/pytest_bdd/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
"""
from __future__ import annotations

import glob
import os.path

import glob2

from .parser import Feature, parse_feature

# Global features dictionary
Expand Down Expand Up @@ -70,7 +69,9 @@ def get_features(paths: list[str], **kwargs) -> list[Feature]:
if path not in seen_names:
seen_names.add(path)
if os.path.isdir(path):
features.extend(get_features(glob2.iglob(os.path.join(path, "**", "*.feature")), **kwargs))
features.extend(
get_features(glob.iglob(os.path.join(path, "**", "*.feature"), recursive=True), **kwargs)
)
else:
base, name = os.path.split(path)
feature = get_feature(base, name, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_bdd/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os.path
from typing import TYPE_CHECKING, cast

import py
from _pytest._io import TerminalWriter
from mako.lookup import TemplateLookup

from .feature import get_features
Expand Down Expand Up @@ -79,7 +79,7 @@ def show_missing_code(config: Config) -> int:

def print_missing_code(scenarios: list[ScenarioTemplate], steps: list[Step]) -> None:
"""Print missing code with TerminalWriter."""
tw = py.io.TerminalWriter()
tw = TerminalWriter()
scenario = step = None

for scenario in scenarios:
Expand Down Expand Up @@ -166,7 +166,7 @@ def group_steps(steps: list[Step]) -> list[Step]:

def _show_missing_code_main(config: Config, session: Session) -> None:
"""Preparing fixture duplicates for output."""
tw = py.io.TerminalWriter()
tw = TerminalWriter()
session.perform_collect()

fm = session._fixturemanager
Expand Down
7 changes: 5 additions & 2 deletions src/pytest_bdd/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ def scenario(


def get_features_base_dir(caller_module_path: str) -> str:
default_base_dir = os.path.dirname(caller_module_path)
return get_from_ini("bdd_features_base_dir", default_base_dir)
d = get_from_ini("bdd_features_base_dir", None)
if d is None:
return os.path.dirname(caller_module_path)
rootdir = CONFIG_STACK[-1].rootpath
return os.path.join(rootdir, d)


def get_from_ini(key: str, default: str) -> str:
Expand Down
5 changes: 2 additions & 3 deletions src/pytest_bdd/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from __future__ import annotations

import argparse
import glob
import os.path
import re

import glob2

from .generation import generate_code, parse_feature_files

MIGRATE_REGEX = re.compile(r"\s?(\w+)\s=\sscenario\((.+)\)", flags=re.MULTILINE)
Expand All @@ -15,7 +14,7 @@
def migrate_tests(args: argparse.Namespace) -> None:
"""Migrate outdated tests to the most recent form."""
path = args.path
for file_path in glob2.iglob(os.path.join(os.path.abspath(path), "**", "*.py")):
for file_path in glob.iglob(os.path.join(os.path.abspath(path), "**", "*.py"), recursive=True):
migrate_tests_in_file(file_path)


Expand Down
2 changes: 1 addition & 1 deletion src/pytest_bdd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def collect_dumped_objects(result: RunResult) -> list:
"""Parse all the objects dumped with `dump_object` from the result.
Note: You must run the result with output to stdout enabled.
For example, using ``testdir.runpytest("-s")``.
For example, using ``pytester.runpytest("-s")``.
"""
stdout = result.stdout.str() # pytest < 6.2, otherwise we could just do str(result.stdout)
payloads = re.findall(rf"{_DUMP_START}(.*?){_DUMP_END}", stdout)
Expand Down
16 changes: 8 additions & 8 deletions tests/args/cfparse/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import textwrap


def test_every_step_takes_param_with_the_same_name(testdir):
def test_every_step_takes_param_with_the_same_name(pytester):
"""Test every step takes param with the same name."""
testdir.makefile(
pytester.makefile(
".feature",
arguments=textwrap.dedent(
"""\
Expand All @@ -21,7 +21,7 @@ def test_every_step_takes_param_with_the_same_name(testdir):
),
)

testdir.makepyfile(
pytester.makepyfile(
textwrap.dedent(
"""\
import pytest
Expand Down Expand Up @@ -53,13 +53,13 @@ def _(euro, values):
"""
)
)
result = testdir.runpytest()
result = pytester.runpytest()
result.assert_outcomes(passed=1)


def test_argument_in_when(testdir):
def test_argument_in_when(pytester):
"""Test step arguments in when steps."""
testdir.makefile(
pytester.makefile(
".feature",
arguments=textwrap.dedent(
"""\
Expand All @@ -72,7 +72,7 @@ def test_argument_in_when(testdir):
),
)

testdir.makepyfile(
pytester.makepyfile(
textwrap.dedent(
"""\
import pytest
Expand Down Expand Up @@ -105,5 +105,5 @@ def _(arguments, arg):
"""
)
)
result = testdir.runpytest()
result = pytester.runpytest()
result.assert_outcomes(passed=1)
16 changes: 8 additions & 8 deletions tests/args/parse/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import textwrap


def test_every_steps_takes_param_with_the_same_name(testdir):
testdir.makefile(
def test_every_steps_takes_param_with_the_same_name(pytester):
pytester.makefile(
".feature",
arguments=textwrap.dedent(
"""\
Expand All @@ -20,7 +20,7 @@ def test_every_steps_takes_param_with_the_same_name(testdir):
),
)

testdir.makepyfile(
pytester.makepyfile(
textwrap.dedent(
"""\
import pytest
Expand Down Expand Up @@ -52,12 +52,12 @@ def _(euro, values):
"""
)
)
result = testdir.runpytest()
result = pytester.runpytest()
result.assert_outcomes(passed=1)


def test_argument_in_when_step_1(testdir):
testdir.makefile(
def test_argument_in_when_step_1(pytester):
pytester.makefile(
".feature",
arguments=textwrap.dedent(
"""\
Expand All @@ -70,7 +70,7 @@ def test_argument_in_when_step_1(testdir):
),
)

testdir.makepyfile(
pytester.makepyfile(
textwrap.dedent(
"""\
import pytest
Expand Down Expand Up @@ -103,5 +103,5 @@ def _(arguments, arg):
"""
)
)
result = testdir.runpytest()
result = pytester.runpytest()
result.assert_outcomes(passed=1)

0 comments on commit 1d88511

Please sign in to comment.