Open watkinsmike opened 1 year ago
I was able to get this working by importing cdk8s directly. I am not sure if this is expected behavior, but I have not seen it documented anywhere that it would be. Leaving open until it is triaged.
from constructs import Construct
import cdk8s
from imports import k8s
class MyChart(cdk8s.Chart):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)
k8s.KubeService(self, "service", spec=k8s.ServiceSpec())
def test_snapshot():
app = cdk8s.Testing.app(yaml_output_type=cdk8s.YamlOutputType.FILE_PER_CHART)
result = cdk8s.Testing.synth(chart=MyChart(app, "test-service"))
assert result[0] == {
"apiVersion": "v1",
"kind": "Service",
"metadata": {"name": "test-service-service-c807c0b4"},
"spec": {},
}
collected 1 item
tests/test_app.py::test_snapshot PASSED [100%]
======================================================================= 1 passed in 0.84s ========================================================================
importing Testing from cdk8s fails with the same test setup:
from cdk8s import Testing, YamlOutputType, Chart
from constructs import Construct
from imports import k8s
class MyChart(Chart):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)
k8s.KubeService(self, "service", spec=k8s.ServiceSpec())
def test_snapshot():
app = Testing.app(yaml_output_type=YamlOutputType.FILE_PER_CHART)
result = Testing.synth(chart=MyChart(app, "test-service"))
assert result[0] == {
"apiVersion": "v1",
"kind": "Service",
"metadata": {"name": "test-service-service-c807c0b4"},
"spec": {},
}
_______________________________________________________ ERROR collecting tests/test_app.py
ERROR tests/test_app.py::Testing - AttributeError: 'Testing' object has no attribute '__jsii_ref__'. Did you mean: '__jsii_type__'?
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================== 1 error in 1.28s ========================================================================
Interesting. Definitely surprising behavior we should investigate. It looks like pytest specific because if I use from cdk8s import Testing
in main.py
, I am able to synth correctly.
@RomainMuller any idea?
Confirm this is still a bug.
This issue has not received any attention in 1 year and will be closed soon. If you want to keep it open, please leave a comment below @mentioning a maintainer.
@RomainMuller @iliapolo Do not close
Confirmed this is still a bug with
python=3.12
cdk8s=2.68.97
pipenv=2024.0.1
Description of the bug:
pytest throws AttributeError on importing Testing from cdk8s
Reproduction Steps:
Error Log:
Environment:
Other:
This is :bug: Bug Report