Running 'pytest -m connection' results in different Python errors

================================== FAILURES ===================================
______________________________ test_basic_movies ______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_basic_movies(client):
    (actual, num_found) = get_movies({}, 0, 20)
  assert num_found == 45993

E assert 33000 == 45993

tests\test_db_connection.py:32: AssertionError
___________________________ test_search_by_movie_id ___________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_search_by_movie_id(client):
    actual = get_movie("573a13eff29313caabdd82f3")
  assert actual['title'] == 'The Martian'

E TypeError: ‘NoneType’ object is not subscriptable

tests\test_db_connection.py:39: TypeError
============================= 39 tests deselected =============================
============= 2 failed, 2 passed, 39 deselected in 19.82 seconds ==============

Do i need to correct the test scripts or import another set of data?
thanks

In this lab you have to modify get_movie() according to the specification wanted. If you get NoneType it is because get_movie() is not returning a movie but something else.

thanks for your reply but there is nothing in this Lab requesting any data modification:
Chapter 1: Driver Setup
Ticket: Connection

I can modify test_db_connection.py but would that be the right step?

I’ve modified test_db_connection.py and now I can run ‘pytest -m connection’ successfully
=================== 4 passed, 39 deselected in 3.99 seconds ===================

but I am not getting a valid data from http://127.0.0.1:5000/status:
Connection: The return from the api was incorrect

I misread the test you were trying to perform.

Modify test_db_connection.py is definitively something you should not do. The web version is not using test_db_connection.py, that’s why http: fails. What ever you did in test_db_connection.py just hid a configuration problem most likely from your .ini file.

here is my config file
[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-1qugt.mongodb.net/test

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-1qugt.mongodb.net/test

From:

I suspect that mongorestore did not successfully completed.

When copying and pasting a large block of logging or code, could you please:

  1. First paste the text.
  2. Select the pasted text.
  3. Then click the button that looks like </>.

That will make the whole block of text legible and have one, uniform formatting. That way we can also immediately search for errors in a much easier way.

Thanks! :smiley:

EDIT: Like so…

================================== FAILURES ===================================
______________________________ test_basic_movies ______________________________

client = &lt;FlaskClient &lt;Flask ‘mflix.factory’&gt;&gt;

```
@pytest.mark.connection
def test_basic_movies(client):
    (actual, num_found) = get_movies({}, 0, 20)
```

> ```
>   assert num_found == 45993
> ```

E assert 33000 == 45993

tests\test_db_connection.py:32: AssertionError
___________________________ test_search_by_movie_id ___________________________

client = &lt;FlaskClient &lt;Flask ‘mflix.factory’&gt;&gt;

```
@pytest.mark.connection
def test_search_by_movie_id(client):
    actual = get_movie("573a13eff29313caabdd82f3")
```

> ```
>   assert actual['title'] == 'The Martian'
> ```

E TypeError: ‘NoneType’ object is not subscriptable

tests\test_db_connection.py:39: TypeError
============================= 39 tests deselected =============================
============= 2 failed, 2 passed, 39 deselected in 19.82 seconds ==============

Yeah, think you’re right…

thanks for your help, I ran mongorestore again and this time it worked just fine

1 Like