Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Running pytest gives " 'cannot import name 'session' " error
#1
I am writing a Python script, which returns topics from a Discourse forum based on a user-entered search query.

CONTEXT

To start, I've built an API wrapper for the Discourse API. The code is available here https://github.com/jasonblais/mattermost-helpdesk

The structure is simple:

.
├── requirements.txt
├── tests
│ ├── test_discourse_wrapper.py // tests my wrapper is working as expected
└── discourse_api_wrapper
│ ├── __init__.py // initializer that creates a requests session used for all HTTP interactions with the Discourse API
│ ├── discourse.py // creates a Discourse class, which makes an API call to Discourse and returns the response

ISSUE

To run the tests I execute this command from the root directory. Note that DISCOURSE_API_KEY is a parameter in discourse_api_wrapper/__init__.py

DISCOURSE_API_KEY='<my-api-key>' python3 -m pytest tests/

I get the following output

Output:
============================= test session starts ============================== platform darwin -- Python 3.7.0, pytest-3.0.3, py-1.6.0, pluggy-0.4.0 rootdir: /.../mattermost-helpdesk, inifile: collected 0 items / 1 errors ==================================== ERRORS ==================================== _______________ ERROR collecting tests/test_discourse_wrapper.py _______________ ImportError while importing test module '/.../mattermost-helpdesk/tests/test_discourse_wrapper.py'. Original error message: 'cannot import name 'session' from 'discourse_api_wrapper' (.../mattermost-helpdesk/discourse_api_wrapper/__init__.py)' Make sure your test modules/packages have valid Python names. !!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!! =========================== 1 error in 0.36 seconds ============================
How do I resolve this error, or troubleshoot it?

I'm new to Python (and programming in general) and doing a Google search didn't resolve it thus far.

Many thanks in advance!
Quote
#2
I don't know how you're getting that error, since you're not trying to import the session. Is the code on github the same code that generates the error?
Quote
#3
Thanks for the reply!

It is the same code, I just pushed it upstream this morning to GitHub before creating this thread.

Could I be missing a package I have to first install for Python?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  pytest-html report customize manoj 4 5,173 Nov-26-2019, 09:10 AM
Last Post: manojshetty
  import error (unknown location) pseudo 1 202 Nov-14-2019, 11:47 PM
Last Post: pseudo
  pytest loop through multiple tests? burvil 0 286 Sep-26-2019, 11:42 PM
Last Post: burvil
  Error when running the second time metro17 3 168 Aug-30-2019, 12:09 PM
Last Post: ThomasL
  error running python in sublime text3 srm 3 345 Jun-22-2019, 09:59 AM
Last Post: srm
  error running script in python3.7.2 interpreter srm 4 552 May-23-2019, 01:09 PM
Last Post: snippsat
  Can I make a session on os.system Serferi 1 285 May-09-2019, 06:20 PM
Last Post: woooee
  Nanpy import error Apretext 2 440 Apr-29-2019, 04:00 PM
Last Post: Apretext
  Syntax Error when running code codeman 3 552 Apr-02-2019, 11:47 AM
Last Post: codeman
  Pytest with requests a21250450 3 423 Mar-21-2019, 03:24 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)