You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: object.__new__() takes exactly one argument (the type to instantiate) #401
I'll update with test and example once I finish the urgent work for work.
the fix was simple just needed the self.get_connection_url() added to the init rather than the constructor
if you have a stack trace for this that would also be helpful, I remember looking at this one and the mongodb client does not throw this error in the constructor, so its not obvious to me where it comes from.
if the bug is in the testcontainers library, presumably it is because we are not waiting for the container correctly or something like that. to be clear your code example is actually this, right:
On 14 Feb 2024, at 11:52, David Ankin ***@***.***> wrote:
if you have a stack trace for this that would also be helpful, I remember looking at this one and the mongodb client does not throw this error in the constructor, so its not obvious to me where it comes from.
if the bug is in the testcontainers library, presumably it is because we are not waiting for the container correctly or something like that. to be clear your code example is actually this, right:
@wait_container_is_ready()
def _connect(self) -> MongoClient:
mc = MongoClient()
mc.__init__(self.get_connection_url())
return mc`
i made it syntax highlight by using this in my markdown:
```python
# code goes here
```
—
Reply to this email directly, view it on GitHub <#401 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BC3KZVOFHBAE2WMQVSR3PDLYTSQPFAVCNFSM6AAAAABAJJE3AWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBTGYZDANZXGM>.
You are receiving this because you modified the open/close state.
--
This email and any attachments are confidential, may contain privileged
material and are intended solely for the use of the individual to whom it
is addressed. Any views or opinions expressed are solely those of the
author and do not necessarily represent those of Covatic. If you are not
the intended recipient of this email, you must neither take any action
based upon its content, nor copy nor show it to anyone.
Covatic is a
limited company registered in England & Wales. Registration number:
10422855. Registered office: 412-413 Scott House, The Custard Factory, Gibb
Street, Birmingham, B9 4AA.
Containerstarted: 731bdd5d5ae4Waitingforcontainer<Container: 731bdd5d5ae4>withimagelocalstack/localstack:2.0.1tobeready ...
testsetupfailed@pytest.fixture(scope='session', autouse=True)deflocalstack():
withLocalStackContainer(
image="localstack/localstack:2.0.1"
).with_bind_ports(
4566, 4566) aslocalstack:
resp=urllib.request.urlopen(f"{localstack.get_url()}/health")
services=json.loads(resp.read().decode())["services"]
# Check that all services are running# assert all(value == "available" for value in services.values())# Check that some of the services keysassertall(test_serviceinservicesfortest_servicein ["dynamodb", "sns", "sqs"])
>s3=localstack.get_client("s3")
EAttributeError: 'LocalStackContainer'objecthasnoattribute'get_client'integration/test_pipelines.py:229: AttributeError
This will fail running as pytest. if you patch localstack with get_client() method then you will get a username and password error and then if you remove the username and password you will get the original error above
importjsonimporturllibimportpytestfromtestcontainers.localstackimportLocalStackContainerfromtestcontainers.mongodbimportMongoDbContainerMONGO_LATEST="mongo:latest"S3_FOLDER="test-bucket"deftest_client_and_brand(mongo_client, mongo_london, mongo_client2, mongo_client1, localstack):
assertlocalstack.get_url() isnotNoneassertmongo_client.get_connection_url() isnotNoneassertmongo_london.get_connection_url() isnotNoneassertmongo_client2.get_connection_url() isnotNoneassertmongo_client1.get_connection_url() isnotNone@pytest.fixture(scope='session', autouse=True)defmongo_client():
withMongoDbContainer(MONGO_LATEST, username='admin', password='admin').with_bind_ports(
27017, 27017) asmongo_client:
yieldmongo_client@pytest.fixture(scope='session', autouse=True)defmongo_london():
withMongoDbContainer(MONGO_LATEST, username='admin', password='admin').with_bind_ports(
27017, 27018) asmongo_london:
yieldmongo_london@pytest.fixture(scope='session', autouse=True)defmongo_client2():
withMongoDbContainer(MONGO_LATEST, username='admin', password='admin').with_bind_ports(
27017, 27019) asmongo_client2:
yieldmongo_client2@pytest.fixture(scope='session', autouse=True)defmongo_client1():
withMongoDbContainer("mongo:latest").with_bind_ports(
27017, 27020) asmongo_client1:
yieldmongo_client1@pytest.fixture(scope='session', autouse=True)deflocalstack():
withLocalStackContainer(
image="localstack/localstack:2.0.1"
).with_bind_ports(
4566, 4566) aslocalstack:
resp=urllib.request.urlopen(f"{localstack.get_url()}/health")
services=json.loads(resp.read().decode())["services"]
# Check that all services are running# assert all(value == "available" for value in services.values())# Check that some of the services keysassertall(test_serviceinservicesfortest_servicein ["dynamodb", "sns", "sqs"])
s3=localstack.get_client("s3")
s3.create_bucket(
Bucket=S3_FOLDER,
CreateBucketConfiguration={"LocationConstraint": "us-west-1"},
)
yieldlocalstack
It's "testcontainers[mongodb]" now
* There is an unreleased fix for mongo waiting - I can merge now and
release it
* There is an open pr for the constructor fix you suggested
Activity
alexanderankin commentedon Dec 12, 2023
can you post a little bit more details on how you got this output? some of your surrounding code maybe?
covatic-john commentedon Dec 12, 2023
I'll update with test and example once I finish the urgent work for work.
the fix was simple just needed the self.get_connection_url() added to the init rather than the constructor
@wait_container_is_ready()
def _connect(self) -> MongoClient:
mc = MongoClient()
mc.init(self.get_connection_url())
return mc`
covatic-john commentedon Feb 14, 2024
This error goes away with 4.0.0rc2
alexanderankin commentedon Feb 14, 2024
Awesome, thanks for testing it! @covatic-john
covatic-john commentedon Feb 14, 2024
Sorry @alexanderankin I hadn't cleared cache and this is still happening. I'll write test case for this and the localstack bug.
alexanderankin commentedon Feb 14, 2024
if you have a stack trace for this that would also be helpful, I remember looking at this one and the mongodb client does not throw this error in the constructor, so its not obvious to me where it comes from.
if the bug is in the testcontainers library, presumably it is because we are not waiting for the container correctly or something like that. to be clear your code example is actually this, right:
i made it syntax highlight by using this in my markdown:
covatic-john commentedon Feb 14, 2024
covatic-john commentedon Feb 14, 2024
OK with 4.0.0rc2 I still get
details
there is a fix for this already submitted. #372
running with 4.0.0.rc2 with patched localstack I get the following error with mongo
If I remove the username and password arguments I am then left with the original error
This will fail running as pytest. if you patch localstack with get_client() method then you will get a username and password error and then if you remove the username and password you will get the original error above
The fix for mongodb is
mongodb/testcontainers/mongodb/init.py
Details
covatic-john commentedon Feb 14, 2024
@alexanderankin hope that covers it :). Now going to see if the docker issue has been fixed in RC2 as I have patched core as well
covatic-john commentedon Feb 14, 2024
totallyzen commentedon Mar 7, 2024
covatic-john commentedon Mar 7, 2024
totallyzen commentedon Mar 7, 2024
Thanks for the help! Not enough time to fix/test everything personally. 💚
covatic-john commentedon Mar 11, 2024
4.0.0 tested Still not fixed needs a release of testcontainers-mongodb
pypi still has 0.0.1rc1. will try installing from main branch
alexanderankin commentedon Mar 11, 2024
covatic-john commentedon Mar 11, 2024
@alexanderankin sorry was busy last week with a P1 and migrations. merging and release would be fantastic 👍
Localstack giving me no issue now with new release :)
alexanderankin commentedon Mar 11, 2024
alexanderankin commentedon Mar 11, 2024
4.0.1 is out (maybe at the expense of our release-please pipeline)
can install testcontainers[mongodb] and see if anything is fixed if not then #448 is back on the table
covatic-john commentedon Mar 11, 2024
nope still same error
covatic-john commentedon Mar 22, 2024
Tested this with the latest release still not working, this fixes the issue it's to do with how you are initialising the mongoclient
I know not pythonistic but it works :)
fix: Pin MongoDB images and improve test coverage for maintained vers…
santi commentedon Apr 2, 2024
Merged another fix here #448, please check it out when it is released in the next package version.
When that happens, please provide: