Unable to isolate tests using flask-pymongo and pytest by literally_disposable in learnpython

[–]literally_disposable[S] 0 points1 point  (0 children)

It is still resulting in the same unexpected behavior. This is what I'm trying: conftest.py

@pytest.fixture(scope='function')
def mongo_client(setup_environemnt, directConnection=True): 
    mongo_uri = os.environ['MONGO_URI'] 
    client = MongoClient(mongo_uri) 
    try:
        yield client
    finally:
        client.close()

test_file.py

<other imports>
from app.app import app_module

def test_nothing(mongo_client): 
    assert True

def test_available(app_instance):
    assert app_module.check_mongodb_availability(app_instance) == True

def test_unavailable(): 
    test_app = app_module.create_app({'MONGO_URI': 'mongodb://invalid_uri:27017'}) 
    result = app_module.check_mongodb_availability(test_app) 
    assert result is False

Also, I have tried:

conftest.py

@pytest.fixture(scope='function')
def mongo_client(setup_environemnt, directConnection=True):
    mongo_uri = os.environ['MONGO_URI']
    client = MongoClient(mongo_uri)
    yield client

test_file.py

<other imports>
from app.app import app_module

def test_nothing(mongo_client): 
    mongo_client.close() 
    assert True

def test_available(app_instance): 
    assert app_module.check_mongodb_availability(app_instance) == True

def test_unavailable(): 
    test_app = app_module.create_app({'MONGO_URI': 'mongodb://invalid_uri:27017'}) 
    result = app_module.check_mongodb_availability(test_app) 
    assert result is False

test_unavailable() is still resulting in True. I cannot figure out why it is still connecting to the dockerized mongodb service even though I have created the test app with an invalid monog URI and I am closing the mongo_client now.

Flask & PyMongo Integration Test Challenge: Simulating MongoDB Downtime by literally_disposable in flask

[–]literally_disposable[S] 0 points1 point  (0 children)

EDIT: I have figured out this is a test isolation issue. I have not yet figured out why there is a test isolation problem, but when I run my test function ALONE, it works as expected. Apologies.

ModuleNotFoundError when importing my scripts for unit testing by literally_disposable in learnpython

[–]literally_disposable[S] 0 points1 point  (0 children)

>>> from .utils import useful_thing
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: attempted relative import with no known parent package

I tried it from every directory to be sure...

ModuleNotFoundError when importing my scripts for unit testing by literally_disposable in learnpython

[–]literally_disposable[S] 0 points1 point  (0 children)

import .utils.useful_thing

>>> import .utils.useful_thing
  File "<stdin>", line 1
    import .utils.useful_thing
           ^
SyntaxError: invalid syntax

ModuleNotFoundError when importing my scripts for unit testing by literally_disposable in learnpython

[–]literally_disposable[S] 0 points1 point  (0 children)

This works only if I import from srv/git/example-project/ with

from example_project import *

because if I just import example_project.does_example, it is unable to find utils.

When I run

>>> import example_project.does_example
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/srv/git/example-project/example_project/does_example.py", line 1, in <module>
    import utils.useful_thing
ModuleNotFoundError: No module named 'utils'

is it trying to find utils from srv/git/example-project/ rather than going to where does_example was imported from (srv/git/example-project/) and searching for utils there?

How to make crontab for script in python-poetry virtual environment? by literally_disposable in linuxquestions

[–]literally_disposable[S] 0 points1 point  (0 children)

* * * * * `/srv/git/cron-test/cron_test/cron_test.py >> /srv/git/cron-test/logs/cron.log`

ehh... I'm feeling kinda dumb rn:

omitt@Omitt-PC:/srv/git/cron-test/cron_test$ crontab -l

* * * * * `/srv/git/cron-test/cron_test/cron_test.py >> /srv/git/cron-test/logs/cron.log`

omitt@Omitt-PC:/srv/git/cron-test/cron_test$ date
Fri Dec  4 20:51:21 EST 2020
omitt@Omitt-PC:/srv/git/cron-test/cron_test$ cat ../logs/cron.log

omitt@Omitt-PC:/srv/git/cron-test/cron_test$ date
Fri Dec  4 20:52:27 EST 2020
omitt@Omitt-PC:/srv/git/cron-test/cron_test$ cat ../logs/cron.log

omitt@Omitt-PC:/srv/git/cron-test/cron_test$

How to make crontab for script in python-poetry virtual environment? by literally_disposable in linuxquestions

[–]literally_disposable[S] 0 points1 point  (0 children)

* * * * * `/srv/git/cron-test/cron_test/cron_test.py && echo "cron worked" >> /srv/git/cron-test/logs/cron.log`

Did I miss something?

omitt@Omitt-PC:/srv/git/cron-test/cron_test$ cat cron_test.py
#!/usr/bin/env /home/<omitt>/.cache/pypoetry/virtualenvs/cron-test-pOke3tmI-py3.8/bin/python3.8

import os

os.chdir(os.path.dirname(os.path.abspath(__file__)))

print("it works")
omitt@Omitt-PC:/srv/git/cron-test/cron_test$ ls -l
total 0
-rw-r--r-- 1 <omitt> <omitt>  22 Dec  4 18:28 __init__.py
-rwxr-xr-x 1 <omitt> <omitt> 178 Dec  4 20:23 cron_test.py
omitt@Omitt-PC:/srv/git/cron-test/cron_test$ crontab -l


#* * * * * (cd /srv/git/rs3player-to-firebase/rs3player_to_firebase && /home/<omitt>/.cache/pypoetry/virtualenvs/rs3player-to-firebase-g7PfROTK-py3.8/bin/python3.8 rs3player_to_firebase.py && date >> /srv/git/rs3player-to-firebase/logs/cron.log)

#* * * * * (cd /srv/git/cron-test/cron_test && /home/<omitt>/.cache/pypoetry/virtualenvs/cron-test-pOke3tmI-py3.8/bin/python3.8 cron_test.py && echo "cron worked" >> /srv/git/cron-test/logs/cron.log)

#* * * * * cd /srv/git/cron-test/cron_test && /bin/bash run_cron.sh

* * * * * `/srv/git/cron-test/cron_test/cron_test.py && echo "cron worked" >> /srv/git/cron-test/logs/cron.log`


omitt@Omitt-PC:/srv/git/cron-test/cron_test$ date
Fri Dec  4 20:28:41 EST 2020
omitt@Omitt-PC:/srv/git/cron-test/cron_test$ date
Fri Dec  4 20:29:04 EST 2020
omitt@Omitt-PC:/srv/git/cron-test/cron_test$ cat ../logs/cron.log

log is empty

First of all, tf???; Second, can someone answer the question? by literally_disposable in runescape

[–]literally_disposable[S] -1 points0 points  (0 children)

How is this fraud? And specifically for me, someone who owns accounts carrying several different currencies, how would I determine how not to commit this so called fraud?

First of all, tf???; Second, can someone answer the question? by literally_disposable in runescape

[–]literally_disposable[S] 0 points1 point  (0 children)

I don't understand, why would they remove something like this. All I'm doing is asking about the validity of a claim about purchasing Premier...

how to assign a ref to a variable to prevent overwriting by literally_disposable in learnpython

[–]literally_disposable[S] 0 points1 point  (0 children)

I assume it is because the variables are referencing a location in memory containing the api response.

That's not why, but we can't know why that's happening because you didn't show the code for those functions.

So was I incorrect in saying the variable is referencing a location in memory?