Bottom Page

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


To start, I've built an API wrapper for the Discourse API. The code is available here

The structure is simple:

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


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

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

I get the following 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/ _______________ ImportError while importing test module '/.../mattermost-helpdesk/tests/'. Original error message: 'cannot import name 'session' from 'discourse_api_wrapper' (.../mattermost-helpdesk/discourse_api_wrapper/' 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!
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?
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?

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)