Skip to content

Commit

Permalink
don't try to use token if it is falsy (#234)
Browse files Browse the repository at this point in the history
* don't try to use `token` if it is falsy

Today it checks specifically if `token` is `None`. It might as well check that it's not `""` either.

* add test for env var with empty token

* changelog entry
  • Loading branch information
timmysilv authored Nov 17, 2022
1 parent 0e336b6 commit b3abb3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

### Bug fixes

* Do not try to connect with an IBMQX token if it is falsy.
[(#234)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/234)

### Contributors

This release contains contributions from (in alphabetical order):

Matthew Silverman

---
# Release 0.27.0

Expand Down
2 changes: 1 addition & 1 deletion pennylane_qiskit/ibmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def connect(kwargs):
url = kwargs.get("ibmqx_url", None) or os.getenv("IBMQX_URL")

# TODO: remove "no cover" when #173 is resolved
if token is not None: # pragma: no cover
if token: # pragma: no cover
# token was provided by the user, so attempt to enable an
# IBM Q account manually
def login():
Expand Down
7 changes: 7 additions & 0 deletions tests/test_ibmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def test_load_kwargs_takes_precedence(token, monkeypatch):
assert dev.provider.credentials.is_ibmq()


def test_load_env_empty_string_has_short_error(monkeypatch):
"""Test that the empty string is treated as a missing token."""
monkeypatch.setenv("IBMQX_TOKEN", "")
with pytest.raises(IBMQAccountError, match="No active IBM Q account"):
IBMQDevice(wires=1)


def test_account_already_loaded(token):
"""Test loading an IBMQ device using
an already loaded account"""
Expand Down

0 comments on commit b3abb3d

Please sign in to comment.