Comments (12)
closed by: #115
from pytest-cpp.
just crafted this minimal thing
import json
import re
import subprocess
from functools import cached_property
from pathlib import Path
from typing import Optional
import pytest
from typing_extensions import TypedDict
build_dir = Path(__file__).parent.parent / "build"
class TestProperty(TypedDict):
name: str
value: str
class TestDefinition(TypedDict):
name: str
properties: list[TestProperty]
class CtestDiscoveryResult(TypedDict):
tests: list[TestDefinition]
class CtestTestCommand:
def __init__(self, test_name: str) -> None:
self._data: list[str] = ["ctest", "-R"]
self.test_name: str = test_name
self.ret_res: Optional[subprocess.CompletedProcess] = None
def add_command(self, command: str):
self._data.append(command)
@cached_property
def failed_log(self) -> str | None:
assert self.ret_res
try:
match = re.findall("(in: )(.*)(\\.log)", self.ret_res.stderr.decode())
log_file = match[0][1]
except IndexError:
return None
return Path(log_file + ".log").resolve(True).read_text()
def run(self) -> None:
self.ret_res = subprocess.run(
[*self._data, self.test_name],
cwd=build_dir.resolve(True),
capture_output=True,
)
def collect_tests() -> list[CtestTestCommand]:
ret: list[CtestTestCommand] = []
res = subprocess.run(
["ctest", "--show-only=json-v1"],
cwd=build_dir.resolve(True),
capture_output=True,
)
data: CtestDiscoveryResult = json.loads(res.stdout)
for test in data["tests"]:
ret.append(CtestTestCommand(test["name"]))
return ret
test_commands = collect_tests()
@pytest.mark.parametrize("command", test_commands, ids=lambda v: v.test_name)
def test_cpp(command: CtestTestCommand):
command.run()
if log_file := command.failed_log:
pytest.fail(msg=f"\n {'-'*8} Test {command.test_name} Failed {'-'*8} \n {log_file}")
Just point it to the build dir and it would do the rest.
from pytest-cpp.
Wow you're fast :) . Thank you. I hope I'll be able to try it out later today.
from pytest-cpp.
No worries, but I like to mention that to encourage someone interested in Catch2 v3 to contribute.
from pytest-cpp.
Should I add Catch2v3Facade, or add it to the existing one?
Whichever is more convenient: if the changes are small and localized, might make sense to add to the existing facade, however if you need to change every single method to do something different, it might make more sense to write a new facade.
from pytest-cpp.
That might be true, but I'm using it with SCons.
from pytest-cpp.
Does your tests gets collected?
from pytest-cpp.
No, it doesn't.
from pytest-cpp.
If it works, happy to review/merge a PR. 👍
from pytest-cpp.
@nicoddemus I don't use any library code though, I just find tests and run them via parameterize
something close to what I suggested in #20
from pytest-cpp.
@nrbnlulu Your code didn't work for me directly, because I don't use ctest
in my project, I needed to call the test binary directly. But it gave me some starting point and I ended up modifying it for my use case ( https://github.com/bluecube/tablog/blob/87506b3b69a873914d6ea726facf4c6c4bf752ec/encoder/tests/test_adapter.py ), so thank you for the push in the right-ish direction :)
I'd still like to have more complete support for v3, though, including specific failed assertions and random generator seed, so I'll try to make a PR.
Should I add Catch2v3Facade
, or add it to the existing one?
from pytest-cpp.
@bluecube AFAIK if you use catch with Cmake it generates ctest binary for you am I wrong?
from pytest-cpp.
Related Issues (20)
- Catch2: escape special characters in test names HOT 1
- Google: Support expected failures HOT 11
- Type-Parametrized Gtests failure HOT 4
- marking cpp test targets. HOT 5
- Collect error when using xdist and temporary .pyc file is deleted
- Ignore python test files maybe? HOT 10
- Skipping invalid test suites HOT 3
- Verbose boost test logging to stdout HOT 6
- C++ tests not collected due to '*_test' mask on Windows HOT 4
- Add a way to use valgrind, catchsegv or similar tool HOT 2
- Add support for Catch testing framework HOT 4
- No skipped message is included in result.xml file
- Key Error after upgrade to 2.1.0 HOT 4
- Getting some warnings with pytest 7.0 HOT 2
- Incompatibility between pytest 6.x and pytest-cpp==2.1.2 HOT 2
- Error when using gtest arguments HOT 5
- Add type-checking with mypy
- Issues if a test exits before xml is created HOT 1
- Add support of prefix-ish parameter to run executable HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-cpp.