Skip to content

Commit

Permalink
Fix relpath compatibility for windows hosts on github
Browse files Browse the repository at this point in the history
  • Loading branch information
elchupanebrej committed Sep 1, 2024
1 parent dca3602 commit e062c23
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/pytest_bdd/compatibility/path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import sys


def relpath(path, start=os.curdir):
try:
return os.path.relpath(path, start)
except ValueError:
if sys.platform == "win32":
return path
else:
raise
3 changes: 2 additions & 1 deletion src/pytest_bdd/message_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
TestStepStarted,
Timestamp,
)
from pytest_bdd.compatibility.path import relpath
from pytest_bdd.compatibility.pytest import (
Config,
FixtureDef,
Expand Down Expand Up @@ -252,7 +253,7 @@ def pytest_fixture_setup(self, fixturedef: FixtureDef, request):
id=cast(PytestBDDIdGeneratorHandler, config).pytest_bdd_id_generator.get_next_id(),
**({"name": hook_name} if hook_name is not None else {}),
source_reference=SourceReference(
uri=os.path.relpath(
uri=relpath(
getfile(func),
str(get_config_root_path(cast(Config, config))),
),
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_bdd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from functools import partial
from itertools import filterfalse
from operator import contains, itemgetter, methodcaller
from os.path import relpath
from pathlib import Path
from typing import Callable, List, Sequence, Set, Tuple, Union

Expand All @@ -13,6 +12,7 @@
from gherkin.pickles.compiler import Compiler as PicklesCompiler

from pytest_bdd.compatibility.parser import ParserProtocol
from pytest_bdd.compatibility.path import relpath
from pytest_bdd.compatibility.pytest import Config
from pytest_bdd.compatibility.struct_bdd import STRUCT_BDD_INSTALLED
from pytest_bdd.exceptions import FeatureError
Expand Down
3 changes: 2 additions & 1 deletion src/pytest_bdd/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def given_beautiful_article(article):
from messages import ExpressionType, Location, Pickle # type:ignore[attr-defined]
from messages import PickleStep as Step # type:ignore[attr-defined]
from messages import SourceReference, StepDefinition, StepDefinitionPattern # type:ignore[attr-defined]
from pytest_bdd.compatibility.path import relpath
from pytest_bdd.compatibility.pytest import Config, Parser, TypeAlias, get_config_root_path
from pytest_bdd.model import Feature, StepType
from pytest_bdd.model.messages_extension import ExpressionType as ExpressionTypeExtension
Expand Down Expand Up @@ -383,7 +384,7 @@ def as_message(self, config: Union[Config, PytestBDDIdGeneratorHandler]):
id=self.id,
pattern=pattern,
source_reference=SourceReference( # type: ignore[call-arg] # migration to pydantic2
uri=os.path.relpath(
uri=relpath(
getfile(self.func),
str(get_config_root_path(cast(Config, config))),
),
Expand Down

0 comments on commit e062c23

Please sign in to comment.