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
  Multiproccessing ValueError: Pool not running when running parallel functions Gilush 0 32 8 hours ago
Last Post: Gilush
  Pytest and rootdirectory Master_Sergius 4 182 Jun-01-2020, 05:05 PM
Last Post: Master_Sergius
  Error: How to to close and restart your shell after running 'conda init' angelica 3 108 May-27-2020, 10:00 AM
Last Post: snippsat
  Which app do I import to fix this error? ErnestTBass 6 259 Apr-26-2020, 08:43 PM
Last Post: snippsat
  Error while humansize module import. johnkgson 3 423 Apr-26-2020, 08:37 AM
Last Post: johnkgson
  pytest in CircleCI filepath error alyflex 0 93 Apr-20-2020, 04:39 PM
Last Post: alyflex
  Cookie and Session JohnnyCoffee 6 358 Apr-14-2020, 02:04 PM
Last Post: JohnnyCoffee
  Importing module from a package results in import error goghvv 2 227 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Error Message Coming Up When Running Code eddywinch82 0 345 Feb-10-2020, 11:48 PM
Last Post: eddywinch82
  Python 2.7 Import error. Directory and filename conflict petcoo00 2 231 Feb-02-2020, 08:46 PM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)